Skip to content

Commit

Permalink
Merge bf2bc57 into 5f457eb
Browse files Browse the repository at this point in the history
  • Loading branch information
drjova committed Nov 28, 2018
2 parents 5f457eb + bf2bc57 commit b78ea93
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 48 deletions.
42 changes: 24 additions & 18 deletions inspire_query_parser/visitors/elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def _generate_author_query(self, author_name):
# ``Mele``) we can improve our filtering in order to filter out results containing records with authors that
# have the same non lastnames prefix, e.g. 'Mele, Samuele'.
if author_name_contains_fullnames(author_name):
logger.info('FULLNAMES {}'.format(author_name))
specialized_author_filter = [
{
'bool': {
Expand All @@ -223,28 +224,33 @@ def _generate_author_query(self, author_name):
in product(name_variations, name_variations)
]

else:
# In the case of initials or even single lastname search, filter with only the name variations.
specialized_author_filter = [
{'term': {ElasticSearchVisitor.AUTHORS_NAME_VARIATIONS_FIELD: name_variation}}
for name_variation in name_variations
]

query = {
'bool': {
'filter': {
'bool': {
'should': specialized_author_filter
query = {
'bool': {
'filter': {
'bool': {
'should': specialized_author_filter
}
},
'must': {
'match': {
ElasticSearchVisitor.KEYWORD_TO_ES_FIELDNAME['author']: author_name
}
}
},
'must': {
'match': {
ElasticSearchVisitor.KEYWORD_TO_ES_FIELDNAME['author']: author_name
}
}
else:
query = {
'bool': {
'must': {
'match': {
ElasticSearchVisitor.KEYWORD_TO_ES_FIELDNAME['author']: {
"query": author_name,
"fuzziness": "AUTO",
}
}
}
}
}
}

return generate_nested_query(ElasticSearchVisitor.AUTHORS_NESTED_QUERY_PATH, query)

def _generate_exact_author_query(self, author_name_or_bai):
Expand Down
38 changes: 8 additions & 30 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,27 +1597,18 @@ def test_elastic_search_visitor_author_lastname():
"path": "authors",
"query": {
"bool": {
"filter": {
"bool": {
"should": [
{
"term": {
"authors.name_variations": "ellis"
}
}
]
}
},
"must": {
"match": {
"authors.full_name": "ellis"
"authors.full_name": {
"query": "ellis",
"fuzziness": "AUTO",
}
}
}
}
}
}
}

generated_es_query = _parse_query(query_str)
assert ordered(generated_es_query) == ordered(expected_query)

Expand All @@ -1629,25 +1620,12 @@ def test_elastic_search_visitor_author_lastname_initial():
"path": "authors",
"query": {
"bool": {
"filter": {
"bool": {
"should": [
{
"term": {
"authors.name_variations": "j ellis"
}
},
{
"term": {
"authors.name_variations": "ellis j"
}
}
]
}
},
"must": {
"match": {
"authors.full_name": "ellis, j"
"authors.full_name": {
"query": "ellis, j",
"fuzziness": "AUTO",
}
}
}
}
Expand Down

0 comments on commit b78ea93

Please sign in to comment.