Last modified: 2011-03-13 18:06:12 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 http://tousauxbalkans.free.fr ). 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). <pre> if (wfRunHooks('SearchOverride', array($this, $term))) { $search =& $this->getSearchEngine(); $titleMatches = $search->searchTitle( $term ); $textMatches = $search->searchText( $term ); ...<snip>... if( $num || $this->offset ) { $wgOut->addHTML( "<p>{$prevnext}</p>\n" ); } } $wgOut->addHTML( $this->powerSearchBox( $term ) ); wfProfileOut( $fname ); </pre> 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.
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?
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 ?
I had also done this, >> SearchMySQL4.php:33: $strictMatching = false; >> SpecialSearch.php:39(+): $search = bpm_extend_search($search);
Extend the existing plugin and override as needed. Using a pluggable mechanism here is a lot cleaner than using a hook.