Page MenuHomePhabricator

Can't search for the number "0" by itself, outside quotes
Closed, ResolvedPublic

Description

I noticed the following code in CirrusSearch:

$term = trim( $term );
// No searching for nothing!  That takes forever!
if ( !$term ) {
	return null;
}

In PHP, '0' converts to false. That means that although https://en.wikipedia.org/w/index.php?search=1&title=Special%3ASearch&fulltext=1 returns plenty of results, https://en.wikipedia.org/w/index.php?search=0&title=Special%3ASearch&fulltext=1 returns none.

Event Timeline

PleaseStand raised the priority of this task from to Needs Triage.
PleaseStand updated the task description. (Show Details)
PleaseStand added a project: CirrusSearch.
PleaseStand changed Security from none to None.
PleaseStand added subscribers: Aklapper, PleaseStand, demon.
demon removed a subscriber: demon.Aug 19 2015, 3:37 PM
Restricted Application added a project: Discovery. · View Herald TranscriptAug 19 2015, 3:37 PM
Cpiral added a subscriber: Cpiral.Jan 15 2016, 7:30 PM

Finding 0 now works. For example:
[0 prefix:mathie](//en.wikipedia.org/wiki/Special:Search/0 prefix:mathie) shows the 68 of the 183 pages in that prefix.

For use in regexp use one of the three escape mechanisms for the zero 0 character or @ character

  • "0"
  • \0
  • [0]
Restricted Application added a subscriber: StudiesWorld. · View Herald TranscriptJan 15 2016, 7:30 PM
Cpiral closed this task as Resolved.Jan 15 2016, 7:31 PM
PleaseStand reopened this task as Open.Jan 16 2016, 1:50 AM

Finding 0 now works. For example:
[0 prefix:mathie](//en.wikipedia.org/wiki/Special:Search/0 prefix:mathie) shows the 68 of the 183 pages in that prefix.

I filed this report specifically to track a bug I had spotted in the CirrusSearch code while reviewing a change to MediaWiki core, not because I was unable to search for "0" at all. The particular link I provided in the description still leads to no results. If I can search for "1", without any punctuation, and get results, I should be able to do the same for "0". However, I am prevented from doing so by the bug I pointed out.

If this is not, as I am thinking, merely the result of a PHP misfeature, I would appreciate an explanation.

PleaseStand renamed this task from Can't search for the number "0" outside quotes to Can't search for the number "0" by itself, outside quotes.Jan 16 2016, 1:51 AM

Change 272311 had a related patch set uploaded (by Gergő Tisza):
Handle '0' search query

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

Change 272311 merged by jenkins-bot:
Handle '0' search query

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

Deskana closed this task as Resolved.Feb 22 2016, 3:57 PM
Deskana added subscribers: Tgr, Deskana.

Thanks, @Tgr!