MediaWiki REL1_31
SearchMssql.php
Go to the documentation of this file.
1<?php
36 function searchText( $term ) {
37 $resultSet = $this->db->query( $this->getQuery( $this->filter( $term ), true ) );
38 return new SqlSearchResultSet( $resultSet, $this->searchTerms );
39 }
40
48 function searchTitle( $term ) {
49 $resultSet = $this->db->query( $this->getQuery( $this->filter( $term ), false ) );
50 return new SqlSearchResultSet( $resultSet, $this->searchTerms );
51 }
52
59 function queryNamespaces() {
60 $namespaces = implode( ',', $this->namespaces );
61 if ( $namespaces == '' ) {
62 $namespaces = '0';
63 }
64 return 'AND page_namespace IN (' . $namespaces . ')';
65 }
66
74 function queryLimit( $sql ) {
75 return $this->db->limitResult( $sql, $this->limit, $this->offset );
76 }
77
86 function queryRanking( $filteredTerm, $fulltext ) {
87 return ' ORDER BY ftindex.[RANK] DESC'; // return ' ORDER BY score(1)';
88 }
89
98 function getQuery( $filteredTerm, $fulltext ) {
99 return $this->queryLimit( $this->queryMain( $filteredTerm, $fulltext ) . ' ' .
100 $this->queryNamespaces() . ' ' .
101 $this->queryRanking( $filteredTerm, $fulltext ) . ' ' );
102 }
103
110 function getIndexField( $fulltext ) {
111 return $fulltext ? 'si_text' : 'si_title';
112 }
113
122 function queryMain( $filteredTerm, $fulltext ) {
123 $match = $this->parseQuery( $filteredTerm, $fulltext );
124 $page = $this->db->tableName( 'page' );
125 $searchindex = $this->db->tableName( 'searchindex' );
126
127 return 'SELECT page_id, page_namespace, page_title, ftindex.[RANK]' .
128 "FROM $page,FREETEXTTABLE($searchindex , $match, LANGUAGE 'English') as ftindex " .
129 'WHERE page_id=ftindex.[KEY] ';
130 }
131
137 function parseQuery( $filteredText, $fulltext ) {
138 global $wgContLang;
139 $lc = $this->legalSearchChars( self::CHARS_NO_SYNTAX );
140 $this->searchTerms = [];
141
142 # @todo FIXME: This doesn't handle parenthetical expressions.
143 $m = [];
144 $q = [];
145
146 if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
147 $filteredText, $m, PREG_SET_ORDER ) ) {
148 foreach ( $m as $terms ) {
149 $q[] = $terms[1] . $wgContLang->normalizeForSearch( $terms[2] );
150
151 if ( !empty( $terms[3] ) ) {
152 $regexp = preg_quote( $terms[3], '/' );
153 if ( $terms[4] ) {
154 $regexp .= "[0-9A-Za-z_]+";
155 }
156 } else {
157 $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
158 }
159 $this->searchTerms[] = $regexp;
160 }
161 }
162
163 $searchon = $this->db->addQuotes( implode( ',', $q ) );
164 $field = $this->getIndexField( $fulltext );
165 return "$field, $searchon";
166 }
167
177 function update( $id, $title, $text ) {
178 // We store the column data as UTF-8 byte order marked binary stream
179 // because we are invoking the plain text IFilter on it so that, and we want it
180 // to properly decode the stream as UTF-8. SQL doesn't support UTF8 as a data type
181 // but the indexer will correctly handle it by this method. Since all we are doing
182 // is passing this data to the indexer and never retrieving it via PHP, this will save space
183 $table = $this->db->tableName( 'searchindex' );
184 $utf8bom = '0xEFBBBF';
185 $si_title = $utf8bom . bin2hex( $title );
186 $si_text = $utf8bom . bin2hex( $text );
187 $sql = "DELETE FROM $table WHERE si_page = $id;";
188 $sql .= "INSERT INTO $table (si_page, si_title, si_text) VALUES ($id, $si_title, $si_text)";
189 return $this->db->query( $sql, 'SearchMssql::update' );
190 }
191
200 function updateTitle( $id, $title ) {
201 $table = $this->db->tableName( 'searchindex' );
202
203 // see update for why we are using the utf8bom
204 $utf8bom = '0xEFBBBF';
205 $si_title = $utf8bom . bin2hex( $title );
206 $sql = "DELETE FROM $table WHERE si_page = $id;";
207 $sql .= "INSERT INTO $table (si_page, si_title, si_text) VALUES ($id, $si_title, 0x00)";
208 return $this->db->query( $sql, 'SearchMssql::updateTitle' );
209 }
210}
to move a page</td >< td > &*You are moving the page across namespaces
Base search engine base class for database-backed searches.
filter( $text)
Return a 'cleaned up' search string.
int[] null $namespaces
static legalSearchChars( $type=self::CHARS_ALL)
Get chars legal for search NOTE: usage as static is deprecated and preserved only as BC measure.
Search engine hook base class for Mssql (ConText).
searchTitle( $term)
Perform a title-only search query and return a result set.
queryMain( $filteredTerm, $fulltext)
Get the base part of the search query.
getQuery( $filteredTerm, $fulltext)
Construct the full SQL query to do the search.
getIndexField( $fulltext)
Picks which field to index on, depending on what type of query.
queryNamespaces()
Return a partial WHERE clause to limit the search to the given namespaces.
searchText( $term)
Perform a full text search query and return a result set.
update( $id, $title, $text)
Create or update the search index record for the given page.
queryRanking( $filteredTerm, $fulltext)
Does not do anything for generic search engine subclasses may define this though.
queryLimit( $sql)
Return a LIMIT clause to limit results on the query.
updateTitle( $id, $title)
Update a search index record's title only.
parseQuery( $filteredText, $fulltext)
This class is used for different SQL-based search engines shipped with MediaWiki.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
For QUnit the mediawiki tests qunit testrunner dependency will be added to any module whereas SearchGetNearMatch runs after $term
Definition hooks.txt:2845