Use locale-aware names for search result reranking#4088
Merged
Conversation
Contributor
Author
lonvia
reviewed
May 6, 2026
Member
lonvia
left a comment
There was a problem hiding this comment.
Looks good in general, just some minor suggestions for code improvements.
Member
|
Please rebase this on master. #4090 contained a few new fixes for mypy. |
When reranking search results, the word matching pool was built only from display_name, which returns the local name (e.g., "Αθήνα" for Athens, Greece). This caused results with translated names to receive unfair distance penalties when the caller used accept-language. Introduce _get_result_rerank_text() which builds the reranking text using locale-aware name resolution from locales.display_name(). This ensures that name variants like name:en are included in the word matching pool when the caller requests a specific language.
Add a test scenario where a place with a non-English local name and an English name:en alias competes against a place with only an English name. Verifies that accept-language=en correctly
- Refines how result labels are aggregated for reranking by using sets of localized names instead of concatenated strings. - Updates tests to reflect improved handling of locale-specific queries.
3fd7bd2 to
01c2c26
Compare
lonvia
reviewed
May 11, 2026
Contributor
Author
|
Ig its good to go... pls have a look now |
lonvia
reviewed
May 15, 2026
Enhances address ranking accuracy by comparing normalized query text against all localized name variants and country code, rather than a single locale name. Reduces false positives and improves ranking for multilingual search scenarios.
Member
|
All good. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Searching for "Athens" with
accept-language: enreturned Athens, Georgia, US before Athens, Greece because the reranking logic useddisplay_namefor word matching, which returned the local Greek name "Αθήνα". This caused a distance penalty for Athens, Greece since "Athens" had no match in the word set.Introduce
_get_result_rerank_text()which builds the reranking text using locale-aware name resolution vialocales.display_name(). This ensures that translated name variants (e.g.,name:en) are included in the word matching pool when the caller specifies a language preference.closes #3871 #4062
AI usage
None
Contributor guidelines (mandatory)