Skip to content

Commit

Permalink
es_visitor: support for legacy jhep/jcap queries
Browse files Browse the repository at this point in the history
* INSPIR-3400
  • Loading branch information
MJedr committed Apr 14, 2020
1 parent bd907de commit b81afce
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
12 changes: 12 additions & 0 deletions inspire_query_parser/visitors/elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ class ElasticSearchVisitor(Visitor):
JOURNAL_VOLUME = 'journal_volume'
JOURNAL_PAGE_START = 'page_start'
JOURNAL_ART_ID = 'artid'
JOURNAL_YEAR = 'year'
JOURNAL_FIELDS_MAPPING = {
JOURNAL_TITLE: '.'.join((JOURNAL_FIELDS_PREFIX, JOURNAL_TITLE)),
JOURNAL_VOLUME: '.'.join((JOURNAL_FIELDS_PREFIX, JOURNAL_VOLUME)),
JOURNAL_PAGE_START: '.'.join((JOURNAL_FIELDS_PREFIX, JOURNAL_PAGE_START)),
JOURNAL_ART_ID: '.'.join((JOURNAL_FIELDS_PREFIX, JOURNAL_ART_ID)),
JOURNAL_YEAR: '.'.join((JOURNAL_FIELDS_PREFIX, JOURNAL_YEAR)),
}
# ########################################

Expand Down Expand Up @@ -518,6 +520,7 @@ def _preprocess_journal_query_value(self, third_journal_field, old_publication_i
self.JOURNAL_TITLE,
self.JOURNAL_VOLUME,
third_journal_field,
self.JOURNAL_YEAR
]
values_list = [
value.strip()
Expand Down Expand Up @@ -574,6 +577,15 @@ def _generate_journal_nested_queries(self, value):
)
)

if self.JOURNAL_YEAR in new_publication_info:
queries_for_each_field.append(
generate_match_query(
self.JOURNAL_FIELDS_MAPPING[self.JOURNAL_YEAR],
new_publication_info[self.JOURNAL_YEAR],
with_operator_and=False
)
)

if third_journal_field in new_publication_info:
artid_or_page_start = new_publication_info[third_journal_field]
match_queries = [
Expand Down
98 changes: 98 additions & 0 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2600,3 +2600,101 @@ def test_nested_query_exact_last_name():

generated_es_query = _parse_query(query_string)
assert generated_es_query == expected_es_query


def test_elastic_search_visitor_type_code_legacy_compatible_jhep_search():
query_str = "j jhep,0903,112,2009"
expected_es_query = {
"nested": {
"path": "publication_info",
"query": {
"bool": {
"must": [
{
"match": {
"publication_info.journal_title": "jhep"
}
},
{
"match": {
"publication_info.journal_volume": "0903"
}
},
{
"match": {
"publication_info.year": "2009"
}
},
{
"bool": {
"should": [
{
"match": {
"publication_info.page_start": "112"
}
},
{
"match": {
"publication_info.artid": "112"
}
}
]
}
}
]
}
}
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_elastic_search_visitor_type_code_legacy_compatible_jcap_search():
query_str = "j jcap,0903,112,2009"
expected_es_query = {
"nested": {
"path": "publication_info",
"query": {
"bool": {
"must": [
{
"match": {
"publication_info.journal_title": "jcap"
}
},
{
"match": {
"publication_info.journal_volume": "0903"
}
},
{
"match": {
"publication_info.year": "2009"
}
},
{
"bool": {
"should": [
{
"match": {
"publication_info.page_start": "112"
}
},
{
"match": {
"publication_info.artid": "112"
}
}
]
}
}
]
}
}
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query

0 comments on commit b81afce

Please sign in to comment.