def suggest(self, **kwargs): """ Did you mean functionality """ suggest = None es_obj = self.es_obj or utils.get_elasticsearch_object() payload = { "index": utils.get_elasticsearch_tor_index(), "doc_type": utils.get_elasticsearch_type(), "size": 0, "body": { "suggest": { "text": kwargs.get('q'), "simple-phrase": { "phrase": { "field": "fancy", "gram_size": 2 # todo make this applicable? } } } } } resp = es_obj.search(**payload) try: suggestions = resp['suggest']['simple-phrase'][0]['options'] if len(suggestions) > 0: suggest = suggestions[0]['text'] except (TypeError, ValueError) as e: logger.exception(e) return suggest
def get_queryset(self, **kwargs): if self.es_obj is None: es_obj = utils.get_elasticsearch_object() hits = es_obj.search(**self.get_es_context(**kwargs)) return self.format_hits(hits)
def get_queryset(self, **kwargs): if self.es_obj is None: es_obj = utils.get_elasticsearch_object() hits = es_obj.search(**self.get_es_context(**kwargs)) return self.format_hits(hits)
def __init__(self): super(BaseCommand, self).__init__() self.es_obj = utils.get_elasticsearch_object() self.es_index = utils.get_elasticsearch_tor_index()