diff --git a/service/src/main/inse/persons/query_builder.py b/service/src/main/inse/persons/query_builder.py index 01bd9343..a258b99a 100644 --- a/service/src/main/inse/persons/query_builder.py +++ b/service/src/main/inse/persons/query_builder.py @@ -275,14 +275,13 @@ def build_authors_search_rescored( } } }, - # { - # "match": { - # "display_name": { - # "query": query, - # "fuzziness": 1 - # } - # } - # } + { + "match": { + "display_name": { + "query": query + } + } + } ], "minimum_should_match": 1 } @@ -473,7 +472,7 @@ def build_authors_search_rescored( functions.append(works_count_boost_query) # Combine query and filters body = {} - + if functions: inner_query = None if query_clause: @@ -486,6 +485,15 @@ def build_authors_search_rescored( } else: inner_query = query_clause + # if query not null then multiply with name matching + body["query"] = { + "function_score": { + "query": inner_query, + "functions": functions, + "score_mode": "multiply", + "boost_mode": "multiply" + } + } else: if filter_clauses: inner_query = { @@ -495,15 +503,15 @@ def build_authors_search_rescored( } else: inner_query = {"match_all": {}} - - body["query"] = { - "function_score": { - "query": inner_query, - "functions": functions, - "score_mode": "multiply", - "boost_mode": "replace" + # if the query is null, replace the scoring completely + body["query"] = { + "function_score": { + "query": inner_query, + "functions": functions, + "score_mode": "multiply", + "boost_mode": "replace" + } } - } else: if query_clause: if filter_clauses: