]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/SearchMySQL4.php
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.git] / includes / SearchMySQL4.php
1 <?php
2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
4 #
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.
9 #
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.
14 #
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 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21  * Search engine hook for MySQL 4+
22  * @addtogroup Search
23  */
24 class SearchMySQL4 extends SearchMySQL {
25         var $strictMatching = true;
26
27         /** @todo document */
28         function SearchMySQL4( $db ) {
29                 $this->db = $db;
30         }
31
32         /** @todo document */
33         function parseQuery( $filteredText, $fulltext ) {
34                 global $wgContLang;
35                 $lc = SearchEngine::legalSearchChars();
36                 $searchon = '';
37                 $this->searchTerms = array();
38
39                 # FIXME: This doesn't handle parenthetical expressions.
40                 $m = array();
41                 if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
42                           $filteredText, $m, PREG_SET_ORDER ) ) {
43                         foreach( $m as $terms ) {
44                                 if( $searchon !== '' ) $searchon .= ' ';
45                                 if( $this->strictMatching && ($terms[1] == '') ) {
46                                         $terms[1] = '+';
47                                 }
48                                 $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] );
49                                 if( !empty( $terms[3] ) ) {
50                                         $regexp = preg_quote( $terms[3], '/' );
51                                         if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+";
52                                 } else {
53                                         $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
54                                 }
55                                 $this->searchTerms[] = $regexp;
56                         }
57                         wfDebug( "Would search with '$searchon'\n" );
58                         wfDebug( 'Match with /\b' . implode( '\b|\b', $this->searchTerms ) . "\b/\n" );
59                 } else {
60                         wfDebug( "Can't understand search query '{$filteredText}'\n" );
61                 }
62
63                 $searchon = $this->db->strencode( $searchon );
64                 $field = $this->getIndexField( $fulltext );
65                 return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) ";
66         }
67 }
68