Skip to content

Commit ec268be

Browse files
committed
🩹 (highlight) Exclude some noisy keyword groups
1 parent 4374bba commit ec268be

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

openaleph_search/query/base.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from openaleph_search.core import get_es
99
from openaleph_search.index.mapping import (
1010
DATE_FORMAT,
11-
GROUPS,
1211
NUMERIC_TYPES,
1312
Field,
1413
get_field_type,
@@ -337,8 +336,19 @@ def get_highlight(self) -> dict[str, Any]:
337336
query = bool_query()
338337
if self.get_query_string():
339338
query["bool"]["should"] = [self.get_query_string()]
339+
# Only highlight filter values that are human-readable text.
340+
# Skip short-code groups (countries, languages, etc.) to avoid
341+
# noisy highlights (e.g. "es" for Spain matching German text).
342+
highlight_groups = {
343+
"names",
344+
"addresses",
345+
"identifiers",
346+
"emails",
347+
"ips",
348+
"phones",
349+
}
340350
for key, values in self.parser.filters.items():
341-
if key in GROUPS or key == Field.NAME:
351+
if key in highlight_groups or key == Field.NAME:
342352
for value in values:
343353
query["bool"]["should"].append(
344354
{

tests/test_search_query.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def test_highlight(self):
160160
"fields": ["text"],
161161
"default_operator": "AND",
162162
"minimum_should_match": "66%",
163+
"allow_leading_wildcard": False,
163164
}
164165
},
165166
},

0 commit comments

Comments
 (0)