Project

General

Profile

« Previous | Next » 

Revision 58309

new portal implemented

View differences:

modules/dli-service-portal/branches/ES_7/requirements.txt
2 2
certifi==2019.3.9
3 3
chardet==3.0.4
4 4
Click==7.0
5
elasticsearch==5.5.3
6
elasticsearch-dsl==5.4.0
5
elasticsearch==7.5.1
6
elasticsearch-dsl==7.1.0
7 7
fastapi==0.20.0
8 8
h11==0.8.1
9 9
httptools==0.0.13
modules/dli-service-portal/branches/ES_7/eu/dnetlib/es_connector.py
100 100
    def __init__(self):
101 101
        props = get_index_properties()
102 102
        self.index_host = [x.strip() for x in props['es_index'].split(',')]
103
        self.client = Elasticsearch(hosts=self.index_host)
103
        self.client = Elasticsearch(hosts=self.index_host, timeout=600000)
104 104
        self.index_name = props['api.index']
105 105

  
106 106
    def get_main_page_stats(self):
107
        stats = dict(total =int(Search(using=self.client, index=self.index_name).doc_type('scholix').count()/2))
107
        stats = dict(total =int(Search(using=self.client, index=self.index_name+"_scholix").count()/2))
108 108
        for item in ['dataset', 'publication']:
109
            s= Search(using=self.client, index=self.index_name).doc_type('object').query(Q('match', typology=item))
109
            s= Search(using=self.client, index=self.index_name+"_object").query(Q('match', typology=item))
110 110
            stats[item] = s.count()
111 111
        return stats
112 112

  
113 113
    def query_by_id(self, id):
114
        s = Search(using=self.client, index=self.index_name).doc_type('object')
114
        s = Search(using=self.client, index=self.index_name+"_object")
115 115
        s = s.query(create_pid_query(id))
116 116
        s.aggs.bucket('typologies', 'terms', field='typology')
117 117
        s.aggs.bucket('all_datasources', 'nested', path='datasources').bucket('all_names', 'terms',
......
160 160
                                        publishers=publishers), hits=hits)
161 161

  
162 162
    def simple_query(self, textual_query, start=None, end=None, user_filter=None):
163
        s = Search(using=self.client, index=self.index_name).doc_type('object')
164

  
163
        s = Search(using=self.client, index=self.index_name+"_object")
165 164
        if not textual_query  == '*':
166
            q = Q('match', _all=textual_query)
165
            q = Q("multi_match", query=textual_query, fields=['title', 'abstract'])
167 166
        else:
168 167
            q = Q()
169 168
        s.aggs.bucket('typologies', 'terms', field='typology')
......
199 198
            s = s[start:end]
200 199
        response = s.execute()
201 200

  
201
        print (response.hits.total)
202

  
202 203
        hits = []
203 204

  
204 205
        for index_result in response.hits:
......
233 234
            if len(tag.key) > 0:
234 235
                publishers.append(dict(key=tag.key, count=tag.doc_count))
235 236

  
236
        return DLIESResponse(total=response.hits.total,
237
        return DLIESResponse(total=s.count(),
237 238
                             facet=dict(pid=pid_types, typology=typologies, datasource=datasources,
238 239
                                        publishers=publishers), hits=hits)
239 240

  
......
242 243
        query_type = Q('nested', path='target', query=Q('bool', must=[Q('match', **args)]))
243 244
        args_id = {'source.dnetIdentifier': object_id}
244 245
        query_for_id = Q('nested', path='source', query=Q('bool', must=[Q('match', **args_id)]))
245
        s = Search(using=self.client).index(self.index_name).doc_type('scholix').query(query_for_id & query_type)
246
        s = Search(using=self.client).index(self.index_name+"_scholix").query(query_for_id & query_type)
246 247
        if start:
247 248
            s = s[start:start + 10]
248 249

  
......
275 276

  
276 277
    def item_by_id(self, id, type=None, start=None):
277 278
        try:
278
            res = self.client.get(index=self.index_name, doc_type='object', id=id)
279
            res = self.client.get(index=self.index_name+"_object", id=id)
279 280
            hits = []
280 281
            input_source = res['_source']
281 282
            fixed_titles = []
modules/dli-service-portal/branches/ES_7/main.py
80 80
    if filter:
81 81
        filter_key = filter
82 82
    if action == 'query' and query is not None:
83
        print(query)
83 84
        connector = DLIESConnector()
84 85
        try:
85 86
            result = connector.simple_query(query, start=start, user_filter=filter_key)

Also available in: Unified diff