From 8ba68a058c99c7a9548146a84156e4859724826f Mon Sep 17 00:00:00 2001 From: Lorenzo Vagliano Date: Thu, 12 Dec 2024 15:10:22 +0100 Subject: [PATCH] fix(es visitor): Removed unnecessary checking for bai_fieldnames Signed-off-by: Lorenzo Vagliano ref: https://github.com/cern-sis/issues-inspire/issues/616 --- .../visitors/elastic_search_visitor.py | 2 +- tests/test_elastic_search_visitor.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/inspire_query_parser/visitors/elastic_search_visitor.py b/inspire_query_parser/visitors/elastic_search_visitor.py index cedc6b0..63f1d8b 100644 --- a/inspire_query_parser/visitors/elastic_search_visitor.py +++ b/inspire_query_parser/visitors/elastic_search_visitor.py @@ -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 diff --git a/tests/test_elastic_search_visitor.py b/tests/test_elastic_search_visitor.py index a848f17..dc48c49 100644 --- a/tests/test_elastic_search_visitor.py +++ b/tests/test_elastic_search_visitor.py @@ -2276,6 +2276,30 @@ 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_nested_query_author_exact_match_affiliation(): query_string = 'aff "Warsaw U. of Tech."' expected_es_query = {