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 15, 2020
1 parent bd907de commit 760ea80
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
13 changes: 12 additions & 1 deletion 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 @@ -517,7 +519,7 @@ def _preprocess_journal_query_value(self, third_journal_field, old_publication_i
publication_info_keys = [
self.JOURNAL_TITLE,
self.JOURNAL_VOLUME,
third_journal_field,
third_journal_field
]
values_list = [
value.strip()
Expand Down Expand Up @@ -574,6 +576,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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
]

install_requires = [
'inspire-schemas~=61.0',
'inspire-schemas~=61.1.3',
'inspire-utils~=3.0,>=3.0.0',
'pypeg2~=2.0,>=2.15.2',
'python-dateutil~=2.0,>=2.6.1',
Expand Down
49 changes: 49 additions & 0 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2600,3 +2600,52 @@ 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_find_journal_with_year():
query_str = "j jhep,0903,112"
expected_es_query = {
"nested": {
"path": "publication_info",
"query": {
"bool": {
"must": [
{
"match": {
"publication_info.journal_title": "jhep"
}
},
{
"match": {
"publication_info.journal_volume": "03"
}
},
{
"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 760ea80

Please sign in to comment.