diff --git a/swh/search/elasticsearch.py b/swh/search/elasticsearch.py --- a/swh/search/elasticsearch.py +++ b/swh/search/elasticsearch.py @@ -145,6 +145,7 @@ 'multi_match': { 'query': url_pattern, 'type': 'bool_prefix', + 'operator': 'and', 'fields': [ 'url.as_you_type', 'url.as_you_type._2gram', diff --git a/swh/search/tests/test_search.py b/swh/search/tests/test_search.py --- a/swh/search/tests/test_search.py +++ b/swh/search/tests/test_search.py @@ -56,6 +56,19 @@ expected_results = ['http://barbaz.qux', 'http://qux.quux'] assert sorted(results) == sorted(expected_results) + def test_origin_url_all_terms(self): + self.search.origin_update([ + {'url': 'http://foo.bar/baz'}, + {'url': 'http://foo.bar/foo.bar'}, + ]) + self.search.flush() + + # Only results containing all terms should be returned. + results = self.search.origin_search(url_pattern='foo bar baz') + assert results == {'next_page_token': None, 'results': [ + {'url': 'http://foo.bar/baz'}, + ]} + def test_origin_with_visit(self): self.search.origin_update([ {'url': 'http://foobar.baz', 'has_visits': True},