Skip to content

Commit

Permalink
Merge pull request #163 from MJedr/texkeys
Browse files Browse the repository at this point in the history
fix texkey query
  • Loading branch information
MJedr authored Mar 2, 2023
2 parents c8e1a35 + 580ad54 commit efc31da
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
Test:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion inspire_query_parser/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
't': 'title',

# texkey
'texkey': 'texkeys',
'texkey': 'texkeys.raw',

# Topcite, i.e. citation count
# Cited used to be for Invenio style syntax while topcite for SPIRES
Expand Down
4 changes: 4 additions & 0 deletions inspire_query_parser/visitors/elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class ElasticSearchVisitor(Visitor):
'refersto': 'references.record.$ref',
'reportnumber': 'report_numbers.value.fuzzy',
'subject': 'facet_inspire_categories',
'texkey': 'texkeys.raw',
'title': 'titles.full_title',
'type-code': 'document_type',
'topcite': 'citation_count',
Expand Down Expand Up @@ -807,6 +808,9 @@ def visit_value(self, node, fieldnames=None):

return generate_match_query(fieldnames, re.sub('ar[xX]iv:', "", node.value), with_operator_and=True)

elif self.KEYWORD_TO_ES_FIELDNAME['texkey'] == fieldnames:
return generate_match_query('texkeys.raw', node.value, with_operator_and=False)

elif fieldnames not in self.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
47 changes: 47 additions & 0 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3235,3 +3235,50 @@ def test_elastic_search_visitor_complex_query():
}
generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_elastic_search_visitor_texkeys_regression():
query_str = "texkey Chen:2014cwa"
expected_es_query = {
"match": {
"texkeys.raw": "Chen:2014cwa"
}
}
generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_elastic_search_visitor_texkeys_regression_bool_query():
query_str = "texkey Chen:2014cwa and a Moskovic"
expected_es_query = {
"bool": {
"must": [
{
"match": {
"texkeys.raw": "Chen:2014cwa"
}
},
{
"nested": {
"path": "authors",
"query": {
"bool": {
"must": [
{
"match": {
"authors.last_name": {
"query": "Moskovic",
"operator": "AND"
}
}
}
]
}
}
}
}
]
}
}
generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query
2 changes: 1 addition & 1 deletion tests/test_restructuring_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@
),
(
'find texkey Hirata:1992*',
KeywordOp(Keyword('texkeys'), Value('Hirata:1992*', contains_wildcard=True))
KeywordOp(Keyword('texkeys.raw'), Value('Hirata:1992*', contains_wildcard=True))
),
# Queries for implicit "and" removal
Expand Down

0 comments on commit efc31da

Please sign in to comment.