Page MenuHomePhabricator

Add a hook to determine in which namespaces titles are searchable
Open, LowPublicFeature

Description

Feature summary (what you would like to be able to do and where):
Add a hook to allow extensions exclude certain namespaces from title-only search queries and search autocomplete, just like SearchableNamespaces.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
Some extensions use random strings in titles, eg. Topic: in StructuredDiscussions (currently searching is disabled), and CommentStreams: in CommentStreams (T276016). Those unreadable titles shouldn't be used in search queries and search autocomplete.

Benefits (why should this be implemented?):
Make users not confused when searching.

Event Timeline

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

Change 930932 had a related patch set uploaded (by 沈澄心; author: 沈澄心):

[mediawiki/core@master] Add a hook to determine in which namespaces titles are searchable

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

Change 930932 abandoned by 沈澄心:

[mediawiki/core@master] Add a hook to determine in which namespaces titles are searchable

Reason:

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

Gehel triaged this task as Low priority.Jun 26 2023, 3:30 PM
Gehel moved this task from needs triage to Feature Requests on the Discovery-Search board.

Out of the 3 completion search APIs offered by MW:

  • action=opensearch via \ApiOpenSearch that defaults to NS_MAIN
  • prefixsearch action=query&list=prefixsearch \ApiQueryPrefixSearch that defaults to NS_MAIN
  • /rest.php/v1/search/title \MediaWiki\Rest\Handler\SearchHandler, defaults to $wgNamespacesToBeSearchedDefault

I believe that the first two are OK as they would display results from the underisable namespace only if explicitly requested by the user (and this is not something that is assisted by the UI, the user have to craft their own API request).
The last one is the one that is being problematic.
If I correctly understood the problem defined in the parent task as:

  • I want to configure my wiki to be able to search for NS_COMMENTSTREAMS by default using Special:Search
    • doable by configuring $wgNamespacesToBeSearchedDefault = [ NS_COMMENTSTREAMS ];
  • But I don't want to have suggestions from NS_COMMENTSTREAMS typing in the autocomplete box
    • This is not doable when the skin is using /rest.php/v1/search/title

To solve this issue I'd suggest introducing another config var (name TBD) similar to $wgNamespacesToBeSearchedDefault but that would instruct the SearchHandler behind /rest.php/v1/search/title a different list of default namespaces to search.
It would become possible to configure a wiki like this:

$wgNamespacesToBeSearchedDefault = [ NS_MAIN, NS_HELP, NS_COMMENTSTREAMS ];
$wgNamespacesToBeSearchedDuringCompletionNameTBDDefault = [ NS_MAIN, NS_HELP ];