From 9269af4c5d823b0dfada210577b3d189f2d67fd8 Mon Sep 17 00:00:00 2001 From: genja Date: Tue, 16 Jun 2026 11:41:59 +0200 Subject: [PATCH] replaced institution autocompletion logic with wildcards --- .../institutions_search_client.py | 69 ++++++++----------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/service/src/main/inse/institutions/institutions_search_client.py b/service/src/main/inse/institutions/institutions_search_client.py index dd895930..7911bac0 100644 --- a/service/src/main/inse/institutions/institutions_search_client.py +++ b/service/src/main/inse/institutions/institutions_search_client.py @@ -99,49 +99,36 @@ class InstitutionsSearchClient: stripped = query_text.strip() must.append({ - "bool": { - "should": [ - # Fast prefix matching via search_as_you_type shingles - { - "multi_match": { - "query": stripped, - "type": "bool_prefix", - "fields": [ - "display_name.search", - "display_name.search._2gram", - "display_name.search._3gram", - "display_name_alternatives.search", - "display_name_alternatives.search._2gram", - ], - "boost": 2, + "bool": { + "should": [ + { + "wildcard": { + "display_name.keyword": { + "value": f"*{stripped}*", + "boost": 2 } - }, - # Exact acronym match — high confidence signal - { - "term": { - "display_name_acronyms.keyword": { - "value": stripped.upper(), - "boost": 10, - } + } + }, + { + "wildcard": { + "display_name_alternatives.keyword": { + "value": f"*{stripped}*", + "boost": 2 } - }, - # Fuzzy fallback for typos (only worth it for longer input) - *( - [{ - "match": { - "display_name": { - "query": stripped, - "fuzziness": "AUTO", - "boost": 1, - } - } - }] - if len(stripped) >= 4 else [] - ), - ], - "minimum_should_match": 1, - } - }) + } + }, + { + "wildcard": { + "display_name_acronyms.keyword": { + "value": f"*{stripped.upper()}*", + "boost": 10 + } + } + } + ], + "minimum_should_match": 1 + } + }) filter_queries = []