def test_should_return_all_results_randomized_for_no_query_param_on_search(self, mock_es): request = testing.DummyRequest() request.context = testing.DummyResource() request.registry.settings['elasticsearch.index'] = 'searchable_items' response = search(request) mock_es.assert_has_calls([mock.call(body={ 'highlight': { 'fields': {'last_name': {}, 'gene_history': {}, 'reference_loci': {}, 'strain': {}, 'synonyms': {}, 'references': {}, 'year': {}, 'keywords': {}, 'secondary_sgdid': {}, 'name_description': {}, 'description': {}, 'first_name': {}, 'mutant_type': {}, 'author': {}, 'cellular_component': {}, 'ec_number': {}, 'chemical': {}, 'go_loci': {}, 'phenotype_loci': {}, 'biological_process': {}, 'qualifier': {}, 'journal': {}, 'molecular_function': {}, 'phenotypes': {}, 'colleague_loci': {}, 'institution': {}, 'observable': {}, 'name': {}, 'tc_number': {}, 'country': {}, 'sequence_history': {}, 'summary': {}, 'position': {}}}, 'query': { 'function_score': { 'query': {'match_all': {}}, 'random_score': {'seed': 12345} }}, '_source': ['name', 'href', 'description', 'category', 'bioentity_id', 'phenotype_loci', 'go_loci', 'reference_loci', 'keys']},from_=0, index='searchable_items', size=10)])
def test_should_return_empty_aggregations_for_unknown_categories(self, mock_format_search, mock_format_aggs, mock_es): mock_es.return_value = { 'hits': { 'total': 10 } } mock_format_search.return_value = [1,2,3] mock_format_aggs.return_value = [3,2,1] request = testing.DummyRequest(params={'limit': 10, 'offset': 25, 'category': 'blablabla'}) request.context = testing.DummyResource() request.registry.settings['elasticsearch.index'] = 'searchable_items' response = search(request) mock_format_aggs.assert_called_with([], 'blablabla', self.category_filters)
def test_should_format_response(self, mock_format_search, mock_format_aggs, mock_es): mock_es.return_value = { 'hits': { 'total': 10 } } mock_format_search.return_value = [1,2,3] mock_format_aggs.return_value = [3,2,1] request = testing.DummyRequest(params={'limit': 10, 'offset': 25, 'category': 'locus'}) request.context = testing.DummyResource() request.registry.settings['elasticsearch.index'] = 'searchable_items' response = search(request) self.assertEqual(response, { 'total': 10, 'results': [1,2,3], 'aggregations': [3,2,1] })
def test_should_apply_pagination(self, mock_es): request = testing.DummyRequest(params={'q': 'eu gene', 'limit': 10, 'offset': 25, 'category': 'unknown'}) request.context = testing.DummyResource() request.registry.settings['elasticsearch.index'] = 'searchable_items' response = search(request) mock_es.assert_called_with(body={ 'sort': ['_score', {'number_annotations': {'order': 'desc'}}], 'highlight': { 'fields': { 'gene_history': {}, 'reference_loci': {}, 'strain': {}, 'synonyms': {}, 'references': {}, 'year': {}, 'secondary_sgdid': {}, 'name_description': {}, 'description': {}, 'mutant_type': {}, 'author': {}, 'cellular_component': {}, 'ec_number': {}, 'chemical': {}, 'go_loci': {}, 'phenotype_loci': {}, 'biological_process': {}, 'qualifier': {}, 'journal': {}, 'molecular_function': {}, 'phenotypes': {}, 'observable': {}, 'name': {}, 'tc_number': {}, 'sequence_history': {}, 'summary': {}, 'first_name': {}, 'last_name': {}, 'institution': {}, 'position': {}, 'country': {}, 'colleague_loci': {}, 'keywords': {}}}, 'query': { 'filtered': { 'filter': { 'bool': { 'must': [{'term': {'category': 'unknown'}}] } }, 'query': { 'bool': { 'minimum_should_match': 1, 'should': [ { "match_phrase_prefix": { "name": { "query": "eu gene", "boost": 3, "max_expansions": 30, "analyzer": "standard" } } }, { "match_phrase_prefix": { "keys": { "query": "eu gene", "boost": 35, "max_expansions": 12, "analyzer": "standard" } } }, { "match_phrase": { "name": { "query": "eu gene", "boost": 80, "analyzer": "standard" } } }, { "match": { "description": { "query": "eu gene", "boost": 1, "analyzer": "standard" } } }, { "match_phrase": { "keys": { "query": "eu gene", "boost": 50, "analyzer": "standard" } } }, { "multi_match": { "query": "eu gene", "type": "best_fields", "fields": ['summary', 'name_description', 'phenotypes', 'cellular_component', 'biological_process', 'molecular_function', 'observable', 'qualifier', 'references', 'phenotype_loci', 'chemical', 'mutant_type', 'go_loci', 'author', 'journal', 'year', 'reference_loci', 'synonyms', 'ec_number', 'gene_history', 'sequence_history', 'secondary_sgdid', 'tc_number', 'strain', 'first_name', 'last_name', 'institution', 'position', 'country', 'colleague_loci', 'keywords'], "boost": 1 } } ] } } }}, '_source': ['name', 'href', 'description', 'category', 'bioentity_id', 'phenotype_loci', 'go_loci', 'reference_loci', 'keys']}, from_=25, index='searchable_items', size=10)