* Removed messages in English, they'll be inherited from the parent.
[lhc/web/wiklou.git] / includes / SearchMySQL3.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 3.23.x
22 * @package MediaWiki
23 * @subpackage Search
24 */
25
26 /** */
27 require_once( 'SearchEngine.php' );
28
29 /**
30 * @package MediaWiki
31 * @subpackage Search
32 */
33 class SearchMySQL3 extends SearchEngine {
34 function SearchMySQL3( &$db ) {
35 $this->db =& $db;
36 }
37
38 function getIndexField( $fulltext ) {
39 return $fulltext ? 'si_text' : 'si_title';
40 }
41
42 function parseQuery( $filteredText, $fulltext ) {
43 global $wgDBminWordLen, $wgContLang;
44
45 $field = $this->getIndexField( $fulltext );
46
47 # on non mysql4 database: get list of words we don't want to search for
48 require_once( 'FulltextStoplist.php' );
49
50 $lc = SearchEngine::legalSearchChars() . '()';
51 $q = preg_replace( "/([()])/", " \\1 ", $filteredText );
52 $q = preg_replace( "/\\s+/", " ", $q );
53 $w = explode( ' ', trim( $q ) );
54
55 $last = $cond = '';
56 foreach ( $w as $word ) {
57 $word = $wgContLang->stripForSearch( $word );
58 if ( 'and' == $word || 'or' == $word || 'not' == $word
59 || '(' == $word || ')' == $word ) {
60 $cond .= ' ' . strtoupper( $word );
61 $last = '';
62 } else if ( strlen( $word ) < $wgDBminWordLen ) {
63 continue;
64 } else if ( FulltextStoplist::inList( $word ) ) {
65 continue;
66 } else {
67 if ( '' != $last ) { $cond .= ' AND'; }
68 $cond .= " (MATCH ($field) AGAINST ('" .
69 $this->db->strencode( $word ). "'))";
70 $last = $word;
71 $this->searchTerms[] = "\\b" . preg_quote( $word, '/' ) . "\\b";
72 }
73 }
74 if ( 0 == count( $this->searchTerms ) ) {
75 # No searchable terms remaining.
76 # We have to return a term for the query or we get an SQL error.
77 return "0";
78 }
79
80 return '(' . $cond . ' )';
81 }
82
83 function queryMain( $filteredTerm, $fulltext ) {
84 $match = $this->parseQuery( $filteredTerm, $fulltext );
85 $page = $this->db->tableName( 'page' );
86 $revision = $this->db->tableName( 'revision' );
87 $text = $this->db->tableName( 'text' );
88 $searchindex = $this->db->tableName( 'searchindex' );
89 return 'SELECT page_id, page_namespace, page_title, old_flags, old_text ' .
90 "FROM $page,$revision,$text,$searchindex " .
91 'WHERE page_id=si_page AND page_latest=rev_id AND rev_text_id=old_id AND ' . $match;
92 }
93
94 function update( $id, $title, $text ) {
95 $dbw=& wfGetDB(DB_MASTER);
96 $dbw->replace( 'searchindex', array(array('si_page')),
97 array(
98 'si_page' => $id,
99 'si_title' => $title,
100 'si_text' => $text
101 ), 'SearchMySQL3::update' );
102 }
103
104 function updateTitle($id,$title) {
105 $dbw=& wfGetDB(DB_MASTER);
106 $lowpri=$dbw->lowPriorityOption();
107 $searchindex = $dbw->tableName( 'searchindex' );
108
109 $sql = "UPDATE $lowpri $searchindex SET si_title='" .
110 $dbw->strencode( $title ) .
111 "' WHERE si_page={$id}";
112
113 $dbw->query( $sql, "SearchMySQL3::updateTitle" );
114 }
115 }
116
117 ?>