Last modified: 2011-03-13 18:06:12 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 4026 - SpecialSearch.php : Using a hook to override search
SpecialSearch.php : Using a hook to override search
Product: MediaWiki
Classification: Unclassified
Search (Other open bugs)
All All
: Lowest enhancement with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
Depends on:
  Show dependency treegraph
Reported: 2005-11-18 23:06 UTC by iubito (Sylvain Machefert)
Modified: 2011-03-13 18:06 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Description iubito (Sylvain Machefert) 2005-11-18 23:06:40 UTC
On my wiki, I needed to add a new search of similar words than the ones searched (for example, search "Yovano" should find "Jovano" and "йовано", search "Katysha" find "Катюша"...).
(this is still in beta, need a lot of improvements, you can see results at ).

To do that, I created an extension with a copy/paste of a piece of code from SpecialSearch for regular searches, plus my own code for guessing similar words.

I'll try to create a patch from CVS if find how to do this, but here I explain the few things I had to change in SpecialSearch :

1) in showResults function, I added the call to SearchOverride hook if exists. 2 parameters : $this = the object SpecialSearch, and $term = the searched word(s).
if (wfRunHooks('SearchOverride', array($this, $term))) {
	$search =& $this->getSearchEngine();
	$titleMatches = $search->searchTitle( $term );
	$textMatches = $search->searchText( $term );


	if( $num || $this->offset ) {
		$wgOut->addHTML( "<p>{$prevnext}</p>\n" );
$wgOut->addHTML( $this->powerSearchBox( $term ) );
wfProfileOut( $fname );

2) function &getSearchEngine() is tagged as private, must be public. My hook need to create a search engine !

3) My hook need also to access to limit, offset, and powerSearchOptions(). Make all them public, not private.
Comment 1 Brion Vibber 2005-11-19 04:12:35 UTC
I don't quite understand the point of this; the whole search engine is 
pluggable by subclassing it and specifying your class in the config.

What is this supposed to do that's different, and why?
Comment 2 iubito (Sylvain Machefert) 2005-11-19 06:45:15 UTC
SpecialSearch does 3 searches :
- if $term is the title of a page -> go to the page
- searchTitle($term)
- searchText($term)

I don't want to change these 3 steps, I just want to add 2 more thins :
- before the search (maybe it's configurable in LocalSettings, how ?) : $search->strictMatching = false;
- after the 3 steps, searchText(MyExtension::getSimilarWords($term))

On the chat, when I asked how to do this, the only way was "create a hook, add if wfRunHooks("searchOverride")...
so I create my hook with a copy/paste of the already existing steps searchTitle($term) and searchText($term).

Is there a way to do what I want without modifying SpecialSearch ?
Comment 3 chris r 2006-07-03 08:22:53 UTC
I had also done this,
>> SearchMySQL4.php:33: $strictMatching = false;
>> SpecialSearch.php:39(+): $search = bpm_extend_search($search);
Comment 4 Rob Church 2007-01-08 13:43:51 UTC
Extend the existing plugin and override as needed. Using a pluggable mechanism
here is a lot cleaner than using a hook.

Note You need to log in before you can comment on or make changes to this bug.