Skip to content

Commit

Permalink
Merge pull request #54 from jankislinger/match-all-query
Browse files Browse the repository at this point in the history
allow 'match_all' queries in FakeSearch
  • Loading branch information
vrcmarcos committed Dec 31, 2020
2 parents 90d5135 + 23530b5 commit 0b54228
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions elasticmock/fake_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def evaluate(self, document):
def _evaluate_for_query_type(self, document):
if self.type == QueryType.MATCH:
return self._evaluate_for_match_query_type(document)
elif self.type == QueryType.MATCH_ALL:
return True
elif self.type == QueryType.TERM:
return self._evaluate_for_term_query_type(document)
elif self.type == QueryType.TERMS:
Expand Down
8 changes: 8 additions & 0 deletions tests/fake_elasticsearch/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def test_should_return_all_documents(self):
search = self.es.search()
self.assertEqual(index_quantity, search.get('hits').get('total'))

def test_should_return_all_documents_match_all(self):
index_quantity = 10
for i in range(0, index_quantity):
self.es.index(index='index_{0}'.format(i), doc_type=DOC_TYPE, body={'data': 'test_{0}'.format(i)})

search = self.es.search(body={'query': {'match_all': {}}})
self.assertEqual(index_quantity, search.get('hits').get('total'))

def test_should_return_only_indexed_documents_on_index(self):
index_quantity = 2
for i in range(0, index_quantity):
Expand Down

0 comments on commit 0b54228

Please sign in to comment.