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