def search(self, query_string, **kwargs): logger.info('search query_string:' + query_string) start_offset = kwargs.get('start_offset') end_offset = kwargs.get('end_offset') search = ArticleDocument.search() \ .query("match", body=query_string) \ .filter('term', status='p') \ .filter('term', type='a') \ [start_offset: end_offset] results = search.execute() return self._process_results(raw_results=results)
def search(self, query_string, **kwargs): logger.info('search query_string:' + query_string) start_offset = kwargs.get('start_offset') end_offset = kwargs.get('end_offset') q = Q('bool', should=[ Q('match', body=query_string), Q('match', title=query_string) ], minimum_should_match="70%") search = ArticleDocument.search() \ .query('bool', filter=[q]) \ .filter('term', status='p') \ .filter('term', type='a') \ .source(False)[start_offset: end_offset] results = search.execute() hits = results['hits'].total raw_results = [] for raw_result in results['hits']['hits']: app_label = 'blog' model_name = 'Article' additional_fields = {} # if 'highlight' in raw_result: # additional_fields['highlighted'] = raw_result['highlight'].get(content_field, '') result_class = SearchResult result = result_class(app_label, model_name, raw_result['_id'], raw_result['_score'], **additional_fields) raw_results.append(result) facets = {} spelling_suggestion = None return { 'results': raw_results, 'hits': hits, 'facets': facets, 'spelling_suggestion': spelling_suggestion, }