Difference between revisions of "Wildcard Search Extension"
From assela Pathirana
Jump to navigationJump to search
(15 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==Background== | ==Background== | ||
By default Mediawiki does not allow wildcard searches by default, but this can be easily turned on. It is possible to do this by changing several line in the Mediawiki code. However, this is not a recommended way, as it will create problems at future updates, etc. This 'extension' allows doing the same without changing the core mediawiki code. | By default Mediawiki does not allow [[wikipedia:Wildcard_character|wildcard]] searches (e.g. searching for <tt>rabbi*</tt> will return pages with rabbit, rabbits or rabbi) by default, but this can be easily turned on. It is possible to do this by changing several line in the Mediawiki code. However, this is not a recommended way, as it will create problems at future updates, etc. This 'extension' allows doing the same without changing the core mediawiki code. | ||
==How to== | ==How to== | ||
*First save this file as SearchMySQLwildcards.php in a sub-folder (let's say 'wildcardsearch' ) of extensions directory. | |||
<nowiki> | |||
</nowiki><pre><nowiki> | </nowiki><pre><nowiki> | ||
<?PHP | <?PHP | ||
#Copyright (C) 2006 Assela Pathirana under the version 2 of the GNU General Public License | #Copyright (C) 2006 Assela Pathirana under the version 2 of the GNU General Public License | ||
#Adds wildcard search functionality to mediawiki | #Adds wildcard search functionality to mediawiki | ||
# file : SearchMySQLwildcards.php | |||
require_once( 'SearchEngine.php' ); | |||
require_once( 'SearchMySQL.php' ); | |||
require_once( 'SearchMySQL4.php' ); | require_once( 'SearchMySQL4.php' ); | ||
//Register this search type and override the default search set in DefaultSettins.php | //Register this search type and override the default search set in DefaultSettins.php | ||
$wgSearchType = SearchMySQLwildcards; | $wgSearchType = SearchMySQLwildcards; | ||
/ | |||
//Create a new search class based on the parent | |||
class SearchMySQLwildcards extends SearchMySQL4 { | class SearchMySQLwildcards extends SearchMySQL4 { | ||
function legalSearchChars() { | function legalSearchChars() { | ||
Line 21: | Line 28: | ||
?> | ?> | ||
</nowiki></pre> | </nowiki></pre> | ||
* Then add the following to the end of your LocalSettings.php file | |||
<nowiki> | |||
</nowiki><pre><nowiki>require_once("extensions/wildcardsearch/SearchMySQLwildcards.php");</nowiki></pre> | |||
;Note: The present code is for MySQL database type. For others changes are necessary. | |||
==Change log== | |||
;<nowiki>08:32, 10 October 2006 (JST)</nowiki>: Made a minor change to make the code compatible with 1.7.1 version of mediawiki. Thanks to ''Lars Pontoppidan'' for the suggestion. | |||
[[Category:Mediawiki Extensions]] | |||
[[Category: |
Latest revision as of 23:34, 9 October 2006
Background
By default Mediawiki does not allow wildcard searches (e.g. searching for rabbi* will return pages with rabbit, rabbits or rabbi) by default, but this can be easily turned on. It is possible to do this by changing several line in the Mediawiki code. However, this is not a recommended way, as it will create problems at future updates, etc. This 'extension' allows doing the same without changing the core mediawiki code.
How to
- First save this file as SearchMySQLwildcards.php in a sub-folder (let's say 'wildcardsearch' ) of extensions directory.
<?PHP #Copyright (C) 2006 Assela Pathirana under the version 2 of the GNU General Public License #Adds wildcard search functionality to mediawiki # file : SearchMySQLwildcards.php require_once( 'SearchEngine.php' ); require_once( 'SearchMySQL.php' ); require_once( 'SearchMySQL4.php' ); //Register this search type and override the default search set in DefaultSettins.php $wgSearchType = SearchMySQLwildcards; //Create a new search class based on the parent class SearchMySQLwildcards extends SearchMySQL4 { function legalSearchChars() { //include + and * as valid characters return "A-Za-z_'0-9¥¥x80-¥¥xFF¥¥-+*"; } } $strictMatching=false; ?>
- Then add the following to the end of your LocalSettings.php file
require_once("extensions/wildcardsearch/SearchMySQLwildcards.php");
- Note
- The present code is for MySQL database type. For others changes are necessary.
Change log
- 08:32, 10 October 2006 (JST)
- Made a minor change to make the code compatible with 1.7.1 version of mediawiki. Thanks to Lars Pontoppidan for the suggestion.