Skip to content

Commit

Permalink
Merge pull request #132 from MJedr/author-match-query
Browse files Browse the repository at this point in the history
visitor: don't use term queries for exact mach queries in authors
  • Loading branch information
MJedr committed May 14, 2020
2 parents cad0f80 + 9e2952b commit 7fa7ef9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 53 deletions.
2 changes: 1 addition & 1 deletion inspire_query_parser/visitors/elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ def visit_exact_match_value(self, node, fieldnames=None):
)
elif self._are_fieldnames_author_or_first_author(fieldnames):
exact_match_queries = [
self._generate_nested_author_query({'term': {field: node.value}}, fieldnames)
self._generate_nested_author_query({'match_phrase': {field: node.value}}, fieldnames)
for field in (bai_fieldnames or fieldnames)
]
else:
Expand Down
90 changes: 38 additions & 52 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_elastic_search_visitor_find_author_exact_value_ellis():
"nested": {
"path": "authors",
"query": {
"term": {
"match_phrase": {
"authors.full_name": "ellis"
}
}
Expand All @@ -109,7 +109,7 @@ def test_elastic_search_visitor_find_first_author_exact_value_ellis():
"nested": {
"path": "first_author",
"query": {
"term": {
"match_phrase": {
"first_author.full_name": "ellis"
}
}
Expand Down Expand Up @@ -768,7 +768,7 @@ def test_elastic_search_visitor_regex_value():


def test_elastic_search_visitor_wildcard_support():
query_str = 'a *alge | a \'alge*\' | a "o*aigh"'
query_str = 'a *alge | a \'alge*\''
expected_es_query = \
{
"bool": {
Expand All @@ -786,31 +786,15 @@ def test_elastic_search_visitor_wildcard_support():
}
},
{
"bool": {
"should": [
{
"nested": {
"path": "authors",
"query": {
"wildcard": {
"authors.full_name": {
"value": "*alge*"
}
}
}
}
},
{
"nested": {
"path": "authors",
"query": {
"term": {
"authors.full_name": "o*aigh"
}
}
"nested": {
"path": "authors",
"query": {
"wildcard": {
"authors.full_name": {
"value": "*alge*"
}
}
]
}
}
}
]
Expand All @@ -822,7 +806,7 @@ def test_elastic_search_visitor_wildcard_support():


def test_elastic_search_visitor_first_author_wildcard_support():
query_str = 'fa *alge | fa \'alge*\' | fa "o*aigh"'
query_str = 'fa *alge | fa \'alge*\''
expected_es_query = \
{
"bool": {
Expand All @@ -840,36 +824,21 @@ def test_elastic_search_visitor_first_author_wildcard_support():
}
},
{
"bool": {
"should": [
{
"nested": {
"path": "first_author",
"query": {
"wildcard": {
"first_author.full_name": {
"value": "*alge*"
}
}
}
}
},
{
"nested": {
"path": "first_author",
"query": {
"term": {
"first_author.full_name": "o*aigh"
}
}
"nested": {
"path": "first_author",
"query": {
"wildcard": {
"first_author.full_name": {
"value": "*alge*"
}
}
]
}
}
}
]
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query

Expand Down Expand Up @@ -1536,7 +1505,7 @@ def test_elastic_search_visitor_handles_bai_exact_value():
"nested": {
"path": "authors",
"query": {
"term": {
"match_phrase": {
"authors.ids.value.raw": "A.Einstein.1"
}
}
Expand All @@ -1554,7 +1523,7 @@ def test_elastic_search_visitor_handles_first_author_bai_exact_value():
"nested": {
"path": "first_author",
"query": {
"term": {
"match_phrase": {
"first_author.ids.value.raw": "A.Einstein.1"
}
}
Expand Down Expand Up @@ -3450,3 +3419,20 @@ def test_wildcard_query_works_with_slash():
}
generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_exact_match_query_for_names():
query_str = 'a "Carloni Calame"'
expected_es_query = {
"nested": {
"path": "authors",
"query": {
"match_phrase": {
"authors.full_name": "Carloni Calame"
}
}
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query

0 comments on commit 7fa7ef9

Please sign in to comment.