Steps to replicate the issue (include links if applicable):
- create an item with multiple aliases that share at least one word, e.g. "The Potato", "Sweet Potato" (Q16176689)
- search for the second alias "Sweet Potato"
What happens?:
- it responds with a search result saying that the alias "The Potato" was matched
What should have happened instead?:
- it responds with a search result saying that the alias "Sweet Potato" was matched
This problem only occurs when part of the search term matches multiple aliases, i.e. the correct alias would be returned as the match if the word "potato" didn't appear in both of them.
It seems that this is considered a match across multiple values, and the match (highlight) that is returned is the first alias containing a word that was part of the search term, even if another alias is a better match. In the example, when searching for "sweet potato" the ElasticSearch response only contains the following value in the highlight field: 8:12-18:18|the potato.
Production example:
At the time of writing (2025-08-07), the behavior outlined above can be observed in the following request: https://www.wikidata.org/w/rest.php/wikibase/v0/search/items?language=en&q=sweet%20potato. It contains an entry for Q16176689 with "match": { "type": "alias", "language": "en", "text": "The Potato" } despite the item having another alias "Sweet Potato" which would be a better match.