mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-08 11:56:59 +00:00
439285e1b7
_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.
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
"""Regression: _extract_entities must find non-ASCII capitalized names.
|
|
|
|
The name extractor used the ASCII-only class [A-Z][a-zA-Z]+, so a query like
|
|
"İstanbul weather" or "Zürich hotels" yielded no name entities at all, and
|
|
"São Paulo" lost "São" — non-English/accented place and proper names were
|
|
silently dropped from query enhancement. Detection is now Unicode-aware;
|
|
ASCII behaviour (including camelCase mid-word capitals not counting as names)
|
|
is preserved.
|
|
"""
|
|
from services.search.query import _extract_entities
|
|
|
|
|
|
def _names(q):
|
|
return _extract_entities(q)["names"]
|
|
|
|
|
|
def test_non_ascii_names_are_extracted():
|
|
assert "İstanbul" in _names("İstanbul weather")
|
|
assert "Zürich" in _names("Zürich hotels")
|
|
assert set(_names("trip to São Paulo")) >= {"São", "Paulo"}
|
|
|
|
|
|
def test_ascii_names_unchanged():
|
|
assert _names("What did Alice do in 2024") == ["Alice"]
|
|
assert _names("news about OpenAI and Google") == ["OpenAI", "Google"]
|
|
|
|
|
|
def test_lowercase_camelcase_and_numbers_are_not_names():
|
|
assert _names("the iphone price") == []
|
|
assert _names("iPhone price") == [] # mid-word capital is not a name
|
|
assert _names("top 50 albums") == []
|