Skip to content

Commit

Permalink
affiliations-id: add support for affiliations-id
Browse files Browse the repository at this point in the history
* INSPIR-3443
  • Loading branch information
monaawi committed Apr 23, 2020
1 parent 0584d60 commit b54c449
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
4 changes: 4 additions & 0 deletions inspire_query_parser/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
'institution': 'affiliation',
'inst': 'affiliation',

# Affiliation Id
'affid': 'affiliation-id',
'affiliation-id': 'affiliation-id',

# Author
'author': 'author',
'au': 'author',
Expand Down
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 @@ -127,6 +127,12 @@ class ElasticSearchVisitor(Visitor):
'type-code': 'document_type',
'topcite': 'citation_count',
'affiliation': 'authors.affiliations.value',
'affiliation-id': [
'authors.affiliations.record.$ref',
'supervisors.affiliations.record.$ref',
'thesis_info.institutions.record.$ref',
'record_affiliations.record.$ref',
],
}
"""Mapping from keywords to ElasticSearch fields.
Note:
Expand Down Expand Up @@ -169,7 +175,7 @@ class ElasticSearchVisitor(Visitor):
DATE_NESTED_QUERY_PATH = 'publication_info'
JOURNAL_NESTED_QUERY_PATH = 'publication_info'
TITLE_SYMBOL_INDICATING_CHARACTER = ['-', '(', ')']
NESTED_FIELDS = ['authors', 'publication_info', 'first_author']
NESTED_FIELDS = ['authors', 'publication_info', 'first_author', 'supervisors']
RECORD_RELATION_FIELD = 'related_records.relation'

# ################
Expand Down Expand Up @@ -789,6 +795,11 @@ def visit_value(self, node, fieldnames=None):
if self.KEYWORD_TO_ES_FIELDNAME['journal'] == fieldnames:
return self._generate_journal_nested_queries(node.value)

if self.KEYWORD_TO_ES_FIELDNAME['affiliation-id'] == fieldnames:
match_queries = [wrap_query_in_nested_if_field_is_nested(generate_match_query(field, node.value, with_operator_and=False), field, self.NESTED_FIELDS)
for field in fieldnames]
return wrap_queries_in_bool_clauses_if_more_than_one(match_queries, use_must_clause=False)

return {
'multi_match': {
'fields': fieldnames,
Expand Down
43 changes: 43 additions & 0 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3223,3 +3223,46 @@ def test_regression_query_with_multiple_dots():

generated_es_query = _parse_query(query_string)
assert generated_es_query == expected_es_query


def test_elastic_search_visitor_affiliation_id():
query_str = 'affid 902666'
expected_es_query = \
{
"bool": {
"should": [
{
"nested": {
"path": "authors",
"query": {
"match": {
"authors.affiliations.record.$ref": "902666"
}
}
}
},
{
"nested": {
"path": "supervisors",
"query": {
"match": {
"supervisors.affiliations.record.$ref": "902666"
}
}
}
},
{
"match": {
"thesis_info.institutions.record.$ref": "902666"
}
},
{
"match": {
"record_affiliations.record.$ref": "902666"
}
}
]
}
}
generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query

0 comments on commit b54c449

Please sign in to comment.