Page MenuHomePhabricator

Special:Search is not searching in the correct namespace
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

What happens?:

  • The results are in multiple namespaces.
  • The results do not respect the -prefix: command within the specified namespace.

What should have happened instead?:

  • The results should not include the mainspace.
  • The results should respect the -prefix: command within the specified namespace.

Event Timeline

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

Thanks for reporting this, the prefix keyword is a bit special in a way that it will take precedence over the namespace filter you might have set in the Special:Search UI. For instance when adding prefix:articles the prefix keyword believes that you want to search for titles in the main namespace and not the wikipedia namespace that you selected in the UI.
Such keywords (that can alter what you selected from the Special:Search UI) are prone to ambiguities and this already caused confusion in the past (T223694) but sadly I'm not sure how to address this properly...
For context, I once tried to fix this ambiguity by adding a warning if the selected namespace is not compatible with the namespace included in the prefix keyword (T193392) but this did not go well broke many existing usecases.
Another approach we took is introducing a new keyword named subpageof which does not require you to add a namespace prefix and will filter on page titles without the namespace, for instance sugpageof:articles will filter all titles that start with articles/ in all the namespaces you selected in the UI.
If I got the intent of your query right a possible work around would be the following query: "Student newspapers" "reliable" -subpageof:"Articles for deletion" -subpageof:"Articles for creation".
Another workaround would be to align the prefix: keyword with the namespace you selected in the UI: "Student newspapers" "reliable" -prefix:wikipedia:articles.

Another workaround, though highly specific to my needs, would be to make the English Wikipedia's 577,000 (and counting) AFD subpages be in a different namespace. ;-)

I wouldn't have been surprised if -prefix:articles had no visible effect. What's surprising is having it override my stated namespace choice.

Yes, that or "Student newspapers" "reliable" -prefix:Wikipedia:Articles would work.

The problem is that -prefix:articles shouldn't change the namespace for the search. Even if it didn't work (i.e., even if it only removed mainspace pages whose title begins with articles, which wouldn't be present in the search results anyway due to choosing a different namespace), it shouldn't be adding mainspace pages to the search results. "Omit pages that start with X" should never result in adding hundreds of pages to the search results.

pfischer subscribed.

A "Please explain this result" button would be nice to have, but until then, we may be able to show at least a warning.

There are two options to solve this:

a) -prefix does not change what is selected as namespaces; if no namespaces follows -prefix: it excludes all titles matching

b) -prefix does not change what is selected as namespaces

Or maybe "if no namespaces follows -prefix, it throws an error message and refuses to search".

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

[mediawiki/extensions/CirrusSearch@master] prefix: do not alter namespaces context when negated

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

Ok the above patch should do the following:

  • when negating a prefix: keyword the namespace of the pages it wants to exclude is not automatically added to the set of namespaces initially selected by the user
  • when negating prefix:keyword if the namespace of the pages it wants to exclude is not selected by the user it will print the following warning: -prefix: is ignored because it excludes pages from a namespace you are not searching in.

Tech-news message (for mediawiki version 1.47.0-wmf.9):
Search: The behavior of the prefix: keyword is slightly changing when used to exclude pages. The prefix: keyword is peculiar in a way that it can extend the list of namespaces you search in, this is particularly confusing when used with a negation because instead of actually filtering pages it might cause more pages to be included.
What is changing:

  • prefix: used without a negation does not change
  • -prefix: used with a negation will stop including the namespace it refers to and may start showing a warning if this namespace is not included in the ones selected from the Special:Search interface. For example the search query -prefix:wikipedia:Article to exclude page titles starting with Wikipedia:Article will start showing a warning and will stop including the Wikipedia namespace if not explicitly selected.

A review of the usage of the prefix: keyword used with a negation showed a very low usage (fewer than 100 search queries in one week across all wikimedia sites). Out of these use-cases none of them seem to be affected by this change.

@dcausse I have provided a rewrite to make the entry more concise and less technical for readers. Please see below and let me know if this version also works. Also please confirm if this update is for Wikipedias only.

An update to Special:Search is refining how the -prefix: operator behaves when used to exclude results. Previously, using -prefix: with negation could unintentionally broaden search results by adding the namespaces included in the search scope, leading to confusing behavior for users expecting a straightforward exclusion filter.

With the update, -prefix: will now strictly exclude matching page titles as intended and may display a warning if the relevant namespace has not been explicitly selected. The behavior of prefix: without negation however remains unchanged.

Tech-news message (for mediawiki version 1.47.0-wmf.9):
Search: The behavior of the prefix: keyword is slightly changing when used to exclude pages. The prefix: keyword is peculiar in a way that it can extend the list of namespaces you search in, this is particularly confusing when used with a negation because instead of actually filtering pages it might cause more pages to be included.
What is changing:

  • prefix: used without a negation does not change
  • -prefix: used with a negation will stop including the namespace it refers to and may start showing a warning if this namespace is not included in the ones selected from the Special:Search interface. For example the search query -prefix:wikipedia:Article to exclude page titles starting with Wikipedia:Article will start showing a warning and will stop including the Wikipedia namespace if not explicitly selected.

A review of the usage of the prefix: keyword used with a negation showed a very low usage (fewer than 100 search queries in one week across all wikimedia sites). Out of these use-cases none of them seem to be affected by this change.

@STei-WMF thanks for the rewrite! This change applies to all WMF wikis not just Wikipedias.

Change #1305601 merged by jenkins-bot:

[mediawiki/extensions/CirrusSearch@master] prefix: do not alter namespaces context when negated

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