Dear Mr. Klein,
did I understand you right that, in order to enable substring search in MediaWiki, one does not have to change anything else than adding the php-file and changing the local settings as you recommended in the last posting?
I had to change two lines where you made references to SearchMySQL to SearchMySQL4. After that the Wiki worked, but the behaviour of the search didn´t change. I still cannot use * or other wild cards.
Do I have to change anything else to make your suggestion work?
Thanks very much in advance for your help.
Regards / mit freundlichen Gruessen
Sebastian Dosch
sebastian.dosch@depre.de
-------------------You wrote:-----------------------
Message: 8
Date: Wed, 28 Sep 2005 12:32:16 +0200
From: Klein.Thomas@eae.com
Subject: RE: [Mediawiki-l] mediawiki 1.4 & 1.5rc4, substring search,
how?
Message-ID:
<OF2A6BE39F.59E045B1-ONC125708A.003933F9-C125708A.0039E2F7@eae.com>
Content-Type: text/plain; charset=ISO-8859-1
Now, here is the class for substring search without to change the source
and MySQL4!
The class SearchMySQL4SubString is a copy of SearchMySQL4.
Make a new file in subdir 'includes' with this name 'SearchMySQL4SubString'
and copy
the next code into this file:
<?php
/**
- Search engine hook for MySQL 4+
- @package MediaWiki
- @subpackage Search
*/
require_once( 'SearchMySQL.php' );
/**
- @package MediaWiki
- @subpackage Search
*/
class SearchMySQL4SubString extends SearchMySQL {
var $strictMatching = true;
/** @todo document */
function SearchMySQL4SubString( &$db ) {
$this->db =& $db;
}
function legalSearchChars() {
return "A-Za-z_'0-9\\x80-\\xFF\\-*?+";
}
/** @todo document */
function parseQuery( $filteredText, $fulltext ) {
global $wgContLang;
$lc = SearchEngine::legalSearchChars();
$searchon = '';
$this->searchTerms = array();
wfDebug( "parseQuery filteredText is: '$filteredText'\n" );
wfDebug( "parseQuery fulltext is: '$fulltext'\n" );
# FIXME: This doesn't handle parenthetical expressions.
if( preg_match_all( '/([-+<>~]?)(([' . $lc .
']+)(*?)|"[^"]*")/',
$filteredText, $m, PREG_SET_ORDER ) ) {
foreach( $m as $terms ) {
if( $searchon !== '' ) $searchon .= ' ';
$searchon .= $terms[1] .
$wgContLang->stripForSearch( $terms[2] );
if( !empty( $terms[3] ) ) {
$regexp = preg_quote( $terms[3], '/' );
if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+";
} else {
$regexp = preg_quote( str_replace( '"', '',
$terms[2] ), '/' );
}
$this->searchTerms[] = $regexp;
}
wfDebug( "Would search with '$searchon'\n" );
wfDebug( "Match with /\b" . implode( '\b|\b',
$this->searchTerms ) . "\b/\n" );
} else {
wfDebug( "Can't understand search query
'{$this->filteredText}'\n" );
}
$searchon = $this->db->strencode( $searchon );
$field = $this->getIndexField( $fulltext );
return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) ";
}
}
?>
And add to lines into your 'LocalSettings.php':
require_once( 'SearchMySQL4SubString.php' );
$wgSearchType = SearchMySQL4SubString;
Now the search function have the same syntax of MySQL4.
Also, see http://dev.mysql.com/doc/mysql/en/fulltext-boolean.html for
details
about full text sql queries in MySQL.
Mit freundlichen Gr|ssen / Kind regards
i.A. Thomas Klein
OPS Koordination / OPS coordination
EAE software GmbH
Kornkamp 8
22926 Ahrensburg/Germany
Tel : +49 4102/480-513
Fax: +49 4102/480-561
e-mail: mailto:klein.thomas@eae.com
mediawiki-l@lists.wikimedia.org