Skip to content

Commit

Permalink
Merge pull request #127 from MJedr/tex-key
Browse files Browse the repository at this point in the history
visitor: add texkey search
  • Loading branch information
MJedr committed Apr 27, 2020
2 parents bf93079 + ce127f6 commit 34347ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
5 changes: 2 additions & 3 deletions inspire_query_parser/visitors/elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,11 @@ def visit_value(self, node, fieldnames=None):
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)
texkey_query = ''
if self.TEXKEY_REGEX.match(colon_value):
texkey_query = self._generate_term_query('texkeys.raw', colon_value, boost=2.0)
return generate_match_query('texkeys.raw', colon_value, with_operator_and=False)
_all_field_query = generate_match_query('_all', colon_value, with_operator_and=True)
query = wrap_queries_in_bool_clauses_if_more_than_one(
[given_field_query, texkey_query, _all_field_query], use_must_clause=False)
[given_field_query, _all_field_query], use_must_clause=False)
return wrap_query_in_nested_if_field_is_nested(query, fieldnames, self.NESTED_FIELDS)

return generate_match_query(fieldnames, node.value, with_operator_and=True)
Expand Down
31 changes: 3 additions & 28 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,34 +531,9 @@ def test_elastic_search_visitor_unknown_keyword_simple_value():
def test_elastic_search_visitor_unknown_keyword_simple_value_maybe_texkey():
query_str = 'smith:2009xj'
expected_es_query = {
"bool": {
"should": [
{
"match": {
"smith": {
"query": "2009xj",
"operator": "and",
}
}
},
{
"term": {
"texkeys.raw": {
"value": "smith:2009xj",
"boost": 2.0,
}
}
},
{
"match": {
"_all": {
"query": "smith:2009xj",
"operator": "and",
}
}
}
]
}
"match":{
"texkeys.raw":"smith:2009xj"
}
}

generated_es_query = _parse_query(query_str)
Expand Down

0 comments on commit 34347ad

Please sign in to comment.