Page MenuHomePhabricator

Search shouldn't trim trailing space when suggesting suggestions
Closed, ResolvedPublic3 Estimated Story PointsBUG REPORT

Description

Steps to replicate the issue:

  • You want to get an article about Go, programming language. Or Go, game. Or anything where "Go" is used as a word, not prefix.
  • You open https://en.wikipedia.org/wiki/Main_Page.
  • You click the search input.
  • You type "Go ". Since you typed that space, you definitely won't see suggestions like "Google". Right? Right?

What happens?

image.png (489×773 px, 81 KB)

What should have happened instead?
If the query ends with a space, you shouldn't get results with the query as a prefix.

Thoughts

  1. This is expecially bad in Wiktionary where you there are a lot of word–prefix collisions. Want to quickly see entries that start with the word word? You're out of luck.

image.png (486×727 px, 28 KB)

  1. Google handles this well.
image.png (792×536 px, 46 KB)
image.png (790×522 px, 44 KB)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

The search term should still be left trimmed. We should only remove right trim.

The search term should still be left trimmed. We should only remove right trim.

Right.

Jack_who_built_the_house renamed this task from Search shouldn't trim space when suggesting suggestions to Search shouldn't trim trailing space when suggesting suggestions.Mar 18 2026, 9:55 AM
Jack_who_built_the_house updated the task description. (Show Details)
Jack_who_built_the_house updated the task description. (Show Details)

The trailing spaces are not trimmed by MW but because the completion algorithm is tokenizing the query and the titles spaces are ignored most of the time.
We can attempt to change the behavior but I'd suggest to run a quick test to see possible undesirable side-effects.
There is also an an issue with wikibase prefix search (which is not using the same algorithm) where trailing spaces are supposed to influence scoring but this got disabled by some custom scoring profiles.
We can fix custom profiles (en, de, es fr) to let trailing spaces influence the ranking but I think this is different from what is requested in T417648.
In T417648 I understand that the trailing space should be used as a signal to tell the search engine to look for "exact" matches on the trimmed search string. The wikibase prefix search should already have a ranking signal on an "exact" label/alias match from the trimmed search string but I suspect the different weights are not doing what we expect in this case.

Change #1267123 had a related patch set uploaded (by DCausse; author: DCausse):

[mediawiki/extensions/CirrusSearch@master] Allow setting the completion tokenizer on the plain field

https://gerrit.wikimedia.org/r/1267123

Change #1267130 had a related patch set uploaded (by DCausse; author: DCausse):

[operations/mediawiki-config@master] search: add space-discount for wikidata custom prefix search profiles

https://gerrit.wikimedia.org/r/1267130

Change #1267123 merged by jenkins-bot:

[mediawiki/extensions/CirrusSearch@master] Allow setting the completion tokenizer on the plain field

https://gerrit.wikimedia.org/r/1267123

Change #1269464 had a related patch set uploaded (by DCausse; author: DCausse):

[operations/mediawiki-config@master] search: add alt. completion indices to test keyword tokenizer (1/2)

https://gerrit.wikimedia.org/r/1269464

Change #1269465 had a related patch set uploaded (by DCausse; author: DCausse):

[operations/mediawiki-config@master] search: add alt. completion indices to test keyword tokenizer (2/2)

https://gerrit.wikimedia.org/r/1269465

Change #1267130 abandoned by DCausse:

[operations/mediawiki-config@master] search: add space-discount for wikidata custom prefix search profiles

Reason:

not needed if I908966a32fc264c5084719337812ca303bac509c is shipped

https://gerrit.wikimedia.org/r/1267130

Change #1269464 merged by jenkins-bot:

[operations/mediawiki-config@master] search: add alt. completion indices to test keyword tokenizer (1/2)

https://gerrit.wikimedia.org/r/1269464

Mentioned in SAL (#wikimedia-operations) [2026-04-29T07:17:19Z] <dcausse@deploy1003> Started scap sync-world: Backport for [[gerrit:1278509|Completion: fix near match field name (T417648)]], [[gerrit:1269464|search: add alt. completion indices to test keyword tokenizer (1/2) (T420427)]]

Mentioned in SAL (#wikimedia-operations) [2026-04-29T07:19:18Z] <dcausse@deploy1003> dcausse: Backport for [[gerrit:1278509|Completion: fix near match field name (T417648)]], [[gerrit:1269464|search: add alt. completion indices to test keyword tokenizer (1/2) (T420427)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2026-04-29T07:24:26Z] <dcausse@deploy1003> Finished scap sync-world: Backport for [[gerrit:1278509|Completion: fix near match field name (T417648)]], [[gerrit:1269464|search: add alt. completion indices to test keyword tokenizer (1/2) (T420427)]] (duration: 07m 07s)

Change #1283037 had a related patch set uploaded (by DCausse; author: DCausse):

[operations/mediawiki-config@master] search: fix alt. completion indices to test keyword tokenizer

https://gerrit.wikimedia.org/r/1283037

Change #1283037 merged by jenkins-bot:

[operations/mediawiki-config@master] search: fix alt. completion indices to test keyword tokenizer

https://gerrit.wikimedia.org/r/1283037

Mentioned in SAL (#wikimedia-operations) [2026-05-06T07:31:24Z] <awight@deploy1003> Started scap sync-world: Backport for [[gerrit:1283101|VE: Avoid counting all refs when listIndex is undefined (T425433)]], [[gerrit:rCICF12830376bd04|search: fix alt. completion indices to test keyword tokenizer (T420427)]], [[gerrit:1283041|search: enable Latin-to-Devanagari transliteration second-chance (T425018)]]

Mentioned in SAL (#wikimedia-operations) [2026-05-06T07:33:20Z] <awight@deploy1003> wmde-fisch, awight, dcausse: Backport for [[gerrit:1283101|VE: Avoid counting all refs when listIndex is undefined (T425433)]], [[gerrit:rCICF12830376bd04|search: fix alt. completion indices to test keyword tokenizer (T420427)]], [[gerrit:1283041|search: enable Latin-to-Devanagari transliteration second-chance (T425018)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can

Mentioned in SAL (#wikimedia-operations) [2026-05-06T07:40:23Z] <awight@deploy1003> Finished scap sync-world: Backport for [[gerrit:1283101|VE: Avoid counting all refs when listIndex is undefined (T425433)]], [[gerrit:rCICF12830376bd04|search: fix alt. completion indices to test keyword tokenizer (T420427)]], [[gerrit:1283041|search: enable Latin-to-Devanagari transliteration second-chance (T425018)]] (duration: 08m 58s)

Change #1269465 merged by jenkins-bot:

[operations/mediawiki-config@master] search: add alt. completion indices to test keyword tokenizer (2/2)

https://gerrit.wikimedia.org/r/1269465

Mentioned in SAL (#wikimedia-operations) [2026-05-07T07:44:20Z] <dcausse@deploy1003> Started scap sync-world: Backport for [[gerrit:1269465|search: add alt. completion indices to test keyword tokenizer (2/2) (T420427)]]

Mentioned in SAL (#wikimedia-operations) [2026-05-07T07:46:22Z] <dcausse@deploy1003> dcausse: Backport for [[gerrit:1269465|search: add alt. completion indices to test keyword tokenizer (2/2) (T420427)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2026-05-07T07:54:06Z] <dcausse@deploy1003> Finished scap sync-world: Backport for [[gerrit:1269465|search: add alt. completion indices to test keyword tokenizer (2/2) (T420427)]] (duration: 09m 46s)

Tested on enwiki and enwiktionary, I don't see any obvious nasty side-effects using a test index (example results https://en.wikipedia.org/w/api.php?action=opensearch&search=go+&cirrusCompletionAltIndexId=1).
Index sizes are equivalent:
eqiad:

green open enwiki_titlesuggest_1778121002         5ex7e_VhSvmQGbp6WsJZsA  4 3  10634814       60   20.4gb    8.1gb
green open enwiki_titlesuggest_alt_1_first        eW_5iR1dRAW3C1aIMdmQfA  4 3  10634814       60   20.4gb    8.1gb
green open enwiktionary_titlesuggest_alt_1_first  qEOBcdIzQZ6dAa5Ed2e-QA  2 2   8837105        0    5.7gb    2.8gb
green open enwiktionary_titlesuggest_1778121692   whajQZggRBClFe6BbNOsJw  2 2   8837105        0    5.7gb    2.8gb

codfw:

green open enwiki_titlesuggest_1778121003         qPa5in8SQ3CcyPPxm1iqDQ  4 3  10634815       60   19.3gb    7.1gb
green open enwiki_titlesuggest_alt_1_first        1Yb13fIlQH-u2758x6VlKA  4 3  10634815       60   20.4gb    8.1gb
green open enwiktionary_titlesuggest_alt_1_first  7sZ_0upiTdGLtVmYzOhz5w  2 2   8837108        0    5.7gb    2.8gb
green open enwiktionary_titlesuggest_1778121724   89YUJOgAQuemLi9UrfwdfA  2 2   8837108        0      5gb    2.1gb

Change #1284628 had a related patch set uploaded (by DCausse; author: DCausse):

[operations/mediawiki-config@master] cirrus: use a keywork tokenizer for the plain field for autocomplete

https://gerrit.wikimedia.org/r/1284628

Change #1284628 merged by jenkins-bot:

[operations/mediawiki-config@master] cirrus: use a keywork tokenizer for the plain field for autocomplete

https://gerrit.wikimedia.org/r/1284628

This is has been deployed and appears to work on the backend but not from the main search widget (works as expected from Special:Search autocomplete), I suspect that some trimming might be happening on the UI, looking into it.

Change #1288455 had a related patch set uploaded (by DCausse; author: DCausse):

[mediawiki/core@master] mediawiki.skinning.typeaheadSearch: keep trailing spaces

https://gerrit.wikimedia.org/r/1288455

Change #1288455 merged by jenkins-bot:

[mediawiki/core@master] mediawiki.skinning.typeaheadSearch: keep trailing spaces

https://gerrit.wikimedia.org/r/1288455

This should now be fixed, only wikidata still seems to trim the trailing space.