Use Doxygen @addtogroup instead of phpdoc @package && @subpackage
[lhc/web/wiklou.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
25 /**
26 * @addtogroup Search
27 */
28 class SearchMySQL4 extends SearchMySQL {
29 var $strictMatching = true;
30
31 /** @todo document */
32 function SearchMySQL4( &$db ) {
33 $this->db =& $db;
34 }
35
36 /** @todo document */
37 function parseQuery( $filteredText, $fulltext ) {
38 global $wgContLang;
39 $lc = SearchEngine::legalSearchChars();
40 $searchon = '';
41 $this->searchTerms = array();
42
43 # FIXME: This doesn't handle parenthetical expressions.
44 $m = array();
45 if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
46 $filteredText, $m, PREG_SET_ORDER ) ) {
47 foreach( $m as $terms ) {
48 if( $searchon !== '' ) $searchon .= ' ';
49 if( $this->strictMatching && ($terms[1] == '') ) {
50 $terms[1] = '+';
51 }
52 $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] );
53 if( !empty( $terms[3] ) ) {
54 $regexp = preg_quote( $terms[3], '/' );
55 if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+";
56 } else {
57 $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
58 }
59 $this->searchTerms[] = $regexp;
60 }
61 wfDebug( "Would search with '$searchon'\n" );
62 wfDebug( 'Match with /\b' . implode( '\b|\b', $this->searchTerms ) . "\b/\n" );
63 } else {
64 wfDebug( "Can't understand search query '{$filteredText}'\n" );
65 }
66
67 $searchon = $this->db->strencode( $searchon );
68 $field = $this->getIndexField( $fulltext );
69 return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) ";
70 }
71 }
72 ?>