Skip to content

Commit

Permalink
Merge pull request #118 from drjova/fix-two-initials
Browse files Browse the repository at this point in the history
authors: fix case for two initials without space
  • Loading branch information
michamos committed Mar 20, 2020
2 parents 483b0ea + 2fb01d5 commit 569d3ae
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inspire_query_parser/utils/visitor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def retokenize_first_names(names):
names_filtered.extend(name.split('.'))
else:
names_filtered.append(name)
return names_filtered
return filter(None, names_filtered)


def is_initial_of_a_name(name_part):
Expand Down
46 changes: 46 additions & 0 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,52 @@ def test_hack_to_split_initial_and_firstname_without_a_space():
assert ordered(generated_es_query) == ordered(expected_query)


def test_hack_to_split_two_initials_without_a_space():
query_str = "a D.K. Smith"
expected_query = {
"nested": {
"path": "authors",
"query": {
"bool": {
"must": [
{
"match": {
"authors.last_name": {
"operator": "AND",
"query": "Smith",
}
}
},
{
"bool": {
"must": [
{
"match": {
"authors.first_name.initials": {
"query": "D",
}
}
},
{
"match": {
"authors.first_name.initials": {
"query": "K",
}
}
}
]
}
},
]
}
},
}
}

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


def test_elastic_search_visitor_author_lastname_initial():
query_str = "a ellis, j"
expected_query = {
Expand Down

0 comments on commit 569d3ae

Please sign in to comment.