fix(search): extract non-ASCII capitalized names in _extract_entities

_extract_entities used the ASCII-only class [A-Z][a-zA-Z]+ to pull name
entities from a query, so non-ASCII names were dropped ("İstanbul",
"Zürich" yielded nothing) or shredded ("São Paulo" -> only "Paulo"),
degrading query enhancement for non-English/accented searches. Match
Unicode words and keep the alphabetic, uppercase-initial ones; ASCII
behaviour (the word boundary already excludes camelCase mid-word
capitals) is unchanged.
This commit is contained in:
Ohualtex
2026-07-04 20:42:06 +03:00
parent 897e6950af
commit 439285e1b7
2 changed files with 39 additions and 2 deletions
+8 -2
View File
@@ -34,8 +34,14 @@ def _extract_entities(query: str) -> Dict[str, List[str]]:
cleaned = query
if qtype:
cleaned = re.sub(rf"^{qtype}\b", "", cleaned, flags=re.I).strip()
for token in re.findall(r"\b[A-Z][a-zA-Z]+\b", cleaned):
entities["names"].append(token)
# Unicode-aware capitalized-word (name) detection. The old [A-Z][a-zA-Z]+
# class missed non-ASCII names like "İstanbul"/"Zürich" (dropped) and
# "São" (shredded). Keep the ASCII behaviour — the word boundary already
# excludes camelCase mid-word capitals — by requiring an all-alphabetic
# token of length > 1 whose first character is uppercase.
for token in re.findall(r"\b\w+\b", cleaned):
if len(token) > 1 and token[0].isupper() and token.isalpha():
entities["names"].append(token)
for year in re.findall(r"\b(?:19|20)\d{2}\b", cleaned):
entities["dates"].append(year)
month_day_year = re.findall(