Skip to content

Commit

Permalink
refersto: add refersto author
Browse files Browse the repository at this point in the history
* INSPIR-3368
  • Loading branch information
monaawi committed Apr 30, 2020
1 parent 34347ad commit af0aaf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions inspire_query_parser/visitors/elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,9 @@ def visit_less_equal_than_op(self, node, fieldnames):

def visit_nested_keyword_op(self, node): # TODO Cannot be completed as of yet.
# FIXME: quick and dirty implementation of refersto:recid:<recid>
if node.left.value == 'refersto':
right = node.right
if hasattr(right, 'left') and hasattr(right, 'right') and right.left.value == 'control_number':
right = node.right
if node.left.value == 'refersto' and hasattr(right, 'left') and hasattr(right, 'right'):
if right.left.value == 'control_number':
recid = right.right.value
citing_records_query = generate_match_query(
self.KEYWORD_TO_ES_FIELDNAME['refersto'],
Expand Down Expand Up @@ -732,7 +732,8 @@ def visit_nested_keyword_op(self, node): # TODO Cannot be completed as of yet.
'must_not': [superseded_records_query, self_citation]
}
}
logger.warning('Nested keyword queries aren\'t implemented yet, except refersto:recid:<recid>')
if right.left.value == 'author':
return generate_match_query("referenced_authors_bais", right.right.value, with_operator_and=False)

def visit_keyword(self, node):
# If no keyword is found, return the original node value (case of an unknown keyword).
Expand Down
13 changes: 13 additions & 0 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,19 @@ def test_nested_refersto_recid_nested_keyword_query():
assert generated_es_query == expected_es_query


def test_nested_refersto_author_nested_keyword_query():
query_str = 'refersto a Jean.L.Picard.1'
expected_es_query = \
{
'match': {
'referenced_authors_bais': 'Jean.L.Picard.1'
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_affiliation_query():
expected_es_query = \
{
Expand Down

0 comments on commit af0aaf1

Please sign in to comment.