2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 * Search engine hook for MySQL 4+
26 require_once( 'SearchMySQL.php' );
32 class SearchMySQL4
extends SearchMySQL
{
33 var $strictMatching = true;
36 function SearchMySQL4( &$db ) {
41 function parseQuery( $filteredText, $fulltext ) {
43 $lc = SearchEngine
::legalSearchChars();
45 $this->searchTerms
= array();
47 # FIXME: This doesn't handle parenthetical expressions.
48 if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
49 $filteredText, $m, PREG_SET_ORDER
) ) {
50 foreach( $m as $terms ) {
51 if( $searchon !== '' ) $searchon .= ' ';
52 if( $this->strictMatching
&& ($terms[1] == '') ) {
55 $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] );
56 if( !empty( $terms[3] ) ) {
57 $regexp = preg_quote( $terms[3], '/' );
58 if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+";
60 $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
62 $this->searchTerms
[] = $regexp;
64 wfDebug( "Would search with '$searchon'\n" );
65 wfDebug( "Match with /\b" . implode( '\b|\b', $this->searchTerms
) . "\b/\n" );
67 wfDebug( "Can't understand search query '{$this->filteredText}'\n" );
70 $searchon = $this->db
->strencode( $searchon );
71 $field = $this->getIndexField( $fulltext );
72 return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) ";