Project

General

Profile

« Previous | Next » 

Revision 49818

Changed portal to scholexplorer

View differences:

es_connector.py
2 2
from elasticsearch import Elasticsearch
3 3
from elasticsearch_dsl import *
4 4

  
5
import os
6
from os import path
5 7

  
8

  
9
def get_property():
10

  
11

  
12
    f = open(path.join(os.path.dirname(os.path.realpath(__file__)), '../../api.properties'))
13
    p = {}
14
    for line in f:
15
        data = line.strip().split("=")
16
        p[data[0].strip()] = data[1].strip()
17
    return p
18

  
19

  
6 20
def create_typology_filter(value):
7 21
    return Q('match', typology=value)
8 22

  
......
11 25
    args = {'localIdentifier.type': value}
12 26
    return Q('nested', path='localIdentifier', query=Q('bool', must=[Q('match', **args)]))
13 27

  
28

  
14 29
def create_publisher_filter(value):
15 30
    return Q('match', publisher=value)
16 31

  
......
35 50

  
36 51

  
37 52
class DLIESConnector(object):
38
    def __init__(self, index_host, index_name):
39
        self.index_host = index_host
40
        self.client = Elasticsearch(hosts=[index_host])
41
        self.index_name = index_name
53
    def __init__(self):
54
        props = get_property()
55
        self.index_host = [x.strip() for x in props['es_index'].split(',')]
56
        self.client = Elasticsearch(hosts=self.index_host)
57
        self.index_name = props['api.index']
42 58

  
43 59
    def simple_query(self, textual_query, start=None, end=None, user_filter=None):
44 60
        s = Search(using=self.client, index=self.index_name).doc_type('object')
......
99 115
                publishers.append(dict(key=tag.key, count=tag.doc_count))
100 116

  
101 117
        return DLIESResponse(total=response.hits.total,
102
                             facet=dict(pid=pid_types, typology=typologies, datasource=datasources, publishers= publishers), hits=hits)
118
                             facet=dict(pid=pid_types, typology=typologies, datasource=datasources,
119
                                        publishers=publishers), hits=hits)
103 120

  
104 121
    def related_type(self, object_id, object_type, start=None):
105 122
        args = {'target.objectType': object_type}

Also available in: Unified diff