Skip to content

Commit

Permalink
Merge pull request #165 from Lorenzovagliano/#616-Searches-are-incorr…
Browse files Browse the repository at this point in the history
…ectly-interpreted-by-query-parser-as-BAI-searches

fix(es visitor): Removed unnecessary checking for bai_fieldnames
  • Loading branch information
drjova authored Dec 12, 2024
2 parents 96d2486 + 49f4808 commit 1af54ee
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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 @@ -954,7 +954,7 @@ def visit_exact_match_value(self, node, fieldnames=None):
else:
exact_match_queries = [
{'match_phrase': {field: node.value}}
for field in (bai_fieldnames or fieldnames)
for field in (fieldnames)
]
query = wrap_queries_in_bool_clauses_if_more_than_one(
exact_match_queries, use_must_clause=False
Expand Down
54 changes: 54 additions & 0 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,60 @@ def test_elastic_search_visitor_PDG_keyword():
assert generated_es_query == expected_es_query


def test_elastic_search_visitor_PDG_keyword_with_dot_character():
query_str = 'keyword "S044.a"'
expected_es_query = {
"match_phrase": {
"keywords.value": "S044.a",
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_elastic_search_visitor_PDG_keyword_with_dot_digit():
query_str = 'keyword "S044.4"'
expected_es_query = {
"match_phrase": {
"keywords.value": "S044.4",
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_elastic_search_visitor_PDG_keyword_with_dot_character_no_quotes():
query_str = 'keyword:S044.a'
expected_es_query = {
"match": {
"keywords.value": {
"query": "S044.a",
"operator": "and"
}
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_elastic_search_visitor_PDG_keyword_with_dot_digit_no_quotes():
query_str = 'keyword:S044.4'
expected_es_query = {
"match": {
"keywords.value": {
"query": "S044.4",
"operator": "and"
}
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_nested_query_author_exact_match_affiliation():
query_string = 'aff "Warsaw U. of Tech."'
expected_es_query = {
Expand Down

0 comments on commit 1af54ee

Please sign in to comment.