Skip to content

Commit

Permalink
Merge 8054080 into ad7e7e3
Browse files Browse the repository at this point in the history
  • Loading branch information
monaawi committed Dec 7, 2018
2 parents ad7e7e3 + 8054080 commit f99d662
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
5 changes: 5 additions & 0 deletions inspire_query_parser/visitors/elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class ElasticSearchVisitor(Visitor):
'title': 'titles.full_title',
'type-code': 'document_type',
'topcite': 'citation_count',
'affiliation': 'authors.affiliations.value',
}
"""Mapping from keywords to ElasticSearch fields.
Expand Down Expand Up @@ -708,6 +709,10 @@ def visit_value(self, node, fieldnames=None):
elif ElasticSearchVisitor.KEYWORD_TO_ES_FIELDNAME['type-code'] == fieldnames:
return self._generate_type_code_query(node.value)

elif ElasticSearchVisitor.KEYWORD_TO_ES_FIELDNAME['affiliation'] == fieldnames:
query = generate_match_query(ElasticSearchVisitor.KEYWORD_TO_ES_FIELDNAME['affiliation'], node.value, with_operator_and=True)
return generate_nested_query(ElasticSearchVisitor.AUTHORS_NESTED_QUERY_PATH, query)

elif fieldnames not in ElasticSearchVisitor.KEYWORD_TO_ES_FIELDNAME.values():
colon_value = ':'.join([fieldnames, node.value])
given_field_query = generate_match_query(fieldnames, node.value, with_operator_and=True)
Expand Down
53 changes: 26 additions & 27 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2224,33 +2224,11 @@ def test_nested_author_fields_query():
"nested": {
"path": "authors",
"query": {
"bool": {
"should": [
{
"match": {
"authors.affiliations.value": {
"operator": "and",
"query": "CERN"
}
}
},
{
"term": {
"texkeys.raw": {
"boost": 2.0,
"value": "authors.affiliations.value:CERN"
}
}
},
{
"match": {
"_all": {
"operator": "and",
"query": "authors.affiliations.value:CERN"
}
}
}
]
"match": {
"authors.affiliations.value": {
"operator": "and",
"query": "CERN"
}
}
}
}
Expand Down Expand Up @@ -2301,3 +2279,24 @@ def test_nested_publication_info_fields_query():

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_affiliation_query():
query_str = 'aff:CERN'
expected_es_query = \
{
"nested": {
"path": "authors",
"query": {
"match": {
"authors.affiliations.value": {
"operator": "and",
"query": "CERN"
}
}
}
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query

0 comments on commit f99d662

Please sign in to comment.