* Fixed unclosed <p> tag
[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 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 * Search engine hook for MySQL 4+
22 * @package MediaWiki
23 * @subpackage Search
24 */
25
26 require_once( 'SearchMySQL.php' );
27
28 /**
29 * @package MediaWiki
30 * @subpackage Search
31 */
32 class SearchMySQL4 extends SearchMySQL {
33 var $strictMatching = true;
34
35 /** @todo document */
36 function SearchMySQL4( &$db ) {
37 $this->db =& $db;
38 }
39
40 /** @todo document */
41 function parseQuery( $filteredText, $fulltext ) {
42 global $wgContLang;
43 $lc = SearchEngine::legalSearchChars();
44 $searchon = '';
45 $this->searchTerms = array();
46
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] == '') ) {
53 $terms[1] = '+';
54 }
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_]+";
59 } else {
60 $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
61 }
62 $this->searchTerms[] = $regexp;
63 }
64 wfDebug( "Would search with '$searchon'\n" );
65 wfDebug( "Match with /\b" . implode( '\b|\b', $this->searchTerms ) . "\b/\n" );
66 } else {
67 wfDebug( "Can't understand search query '{$this->filteredText}'\n" );
68 }
69
70 $searchon = $this->db->strencode( $searchon );
71 $field = $this->getIndexField( $fulltext );
72 return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) ";
73 }
74 }
75 ?>