MediaWiki  1.23.14
SearchMssql.php
Go to the documentation of this file.
1 <?php
28 class SearchMssql extends SearchDatabase {
36  function searchText( $term ) {
37  $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), true ) ) );
38  return new MssqlSearchResultSet( $resultSet, $this->searchTerms );
39  }
40 
48  function searchTitle( $term ) {
49  $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
50  return new MssqlSearchResultSet( $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 
84  function queryRanking( $filteredTerm, $fulltext ) {
85  return ' ORDER BY ftindex.[RANK] DESC'; // return ' ORDER BY score(1)';
86  }
87 
96  function getQuery( $filteredTerm, $fulltext ) {
97  return $this->queryLimit( $this->queryMain( $filteredTerm, $fulltext ) . ' ' .
98  $this->queryNamespaces() . ' ' .
99  $this->queryRanking( $filteredTerm, $fulltext ) . ' ' );
100  }
101 
108  function getIndexField( $fulltext ) {
109  return $fulltext ? 'si_text' : 'si_title';
110  }
111 
120  function queryMain( $filteredTerm, $fulltext ) {
121  $match = $this->parseQuery( $filteredTerm, $fulltext );
122  $page = $this->db->tableName( 'page' );
123  $searchindex = $this->db->tableName( 'searchindex' );
124 
125  return 'SELECT page_id, page_namespace, page_title, ftindex.[RANK]' .
126  "FROM $page,FREETEXTTABLE($searchindex , $match, LANGUAGE 'English') as ftindex " .
127  'WHERE page_id=ftindex.[KEY] ';
128  }
129 
133  function parseQuery( $filteredText, $fulltext ) {
136  $this->searchTerms = array();
137 
138  # @todo FIXME: This doesn't handle parenthetical expressions.
139  $m = array();
140  $q = array();
141 
142  if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
143  $filteredText, $m, PREG_SET_ORDER ) ) {
144  foreach ( $m as $terms ) {
145  $q[] = $terms[1] . $wgContLang->normalizeForSearch( $terms[2] );
146 
147  if ( !empty( $terms[3] ) ) {
148  $regexp = preg_quote( $terms[3], '/' );
149  if ( $terms[4] ) {
150  $regexp .= "[0-9A-Za-z_]+";
151  }
152  } else {
153  $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
154  }
155  $this->searchTerms[] = $regexp;
156  }
157  }
158 
159  $searchon = $this->db->strencode( join( ',', $q ) );
160  $field = $this->getIndexField( $fulltext );
161  return "$field, '$searchon'";
162  }
163 
173  function update( $id, $title, $text ) {
174  // We store the column data as UTF-8 byte order marked binary stream
175  // because we are invoking the plain text IFilter on it so that, and we want it
176  // to properly decode the stream as UTF-8. SQL doesn't support UTF8 as a data type
177  // but the indexer will correctly handle it by this method. Since all we are doing
178  // is passing this data to the indexer and never retrieving it via PHP, this will save space
179  $table = $this->db->tableName( 'searchindex' );
180  $utf8bom = '0xEFBBBF';
181  $si_title = $utf8bom . bin2hex( $title );
182  $si_text = $utf8bom . bin2hex( $text );
183  $sql = "DELETE FROM $table WHERE si_page = $id;";
184  $sql .= "INSERT INTO $table (si_page, si_title, si_text) VALUES ($id, $si_title, $si_text)";
185  return $this->db->query( $sql, 'SearchMssql::update' );
186  }
187 
196  function updateTitle( $id, $title ) {
197  $table = $this->db->tableName( 'searchindex' );
198 
199  // see update for why we are using the utf8bom
200  $utf8bom = '0xEFBBBF';
201  $si_title = $utf8bom . bin2hex( $title );
202  $sql = "DELETE FROM $table WHERE si_page = $id;";
203  $sql .= "INSERT INTO $table (si_page, si_title, si_text) VALUES ($id, $si_title, 0x00)";
204  return $this->db->query( $sql, 'SearchMssql::updateTitle' );
205  }
206 }
207 
212  function __construct( $resultSet, $terms ) {
213  $this->mResultSet = $resultSet;
214  $this->mTerms = $terms;
215  }
216 
217  function termMatches() {
218  return $this->mTerms;
219  }
220 
221  function numRows() {
222  return $this->mResultSet->numRows();
223  }
224 
225  function next() {
226  $row = $this->mResultSet->fetchObject();
227  if ( $row === false ) {
228  return false;
229  }
230  return new SearchResult( $row );
231  }
232 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SearchMssql
Search engine hook base class for Mssql (ConText).
Definition: SearchMssql.php:28
SearchMssql\queryLimit
queryLimit( $sql)
Return a LIMIT clause to limit results on the query.
Definition: SearchMssql.php:74
SearchMssql\queryMain
queryMain( $filteredTerm, $fulltext)
Get the base part of the search query.
Definition: SearchMssql.php:120
MssqlSearchResultSet\numRows
numRows()
Definition: SearchMssql.php:221
MssqlSearchResultSet\__construct
__construct( $resultSet, $terms)
Definition: SearchMssql.php:212
$wgContLang
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 content language as $wgContLang
Definition: design.txt:56
SearchMssql\searchTitle
searchTitle( $term)
Perform a title-only search query and return a result set.
Definition: SearchMssql.php:48
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1530
SearchDatabase
Base search engine base class for database-backed searches.
Definition: SearchDatabase.php:29
namespaces
to move a page</td >< td > &*You are moving the page across namespaces
Definition: All_system_messages.txt:2677
SearchMssql\searchText
searchText( $term)
Perform a full text search query and return a result set.
Definition: SearchMssql.php:36
SearchResult
Definition: SearchResult.php:30
SearchMssql\getQuery
getQuery( $filteredTerm, $fulltext)
Construct the full SQL query to do the search.
Definition: SearchMssql.php:96
MssqlSearchResultSet\next
next()
Fetches next search result, or false.
Definition: SearchMssql.php:225
SearchMssql\updateTitle
updateTitle( $id, $title)
Update a search index record's title only.
Definition: SearchMssql.php:196
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
SearchResultSet
Definition: SearchResultSet.php:27
$regexp
$regexp
Definition: mwdoc-filter.php:19
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
SearchMssql\parseQuery
parseQuery( $filteredText, $fulltext)
Definition: SearchMssql.php:133
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
SearchMssql\queryRanking
queryRanking( $filteredTerm, $fulltext)
Does not do anything for generic search engine subclasses may define this though.
Definition: SearchMssql.php:84
SearchEngine\legalSearchChars
static legalSearchChars()
Definition: SearchEngine.php:256
SearchMssql\update
update( $id, $title, $text)
Create or update the search index record for the given page.
Definition: SearchMssql.php:173
SearchEngine\$namespaces
$namespaces
Definition: SearchEngine.php:37
MssqlSearchResultSet
Definition: SearchMssql.php:211
MssqlSearchResultSet\termMatches
termMatches()
Fetch an array of regular expression fragments for matching the search terms as parsed by this engine...
Definition: SearchMssql.php:217
$term
the value to return A Title object or null whereas SearchGetNearMatch runs after $term
Definition: hooks.txt:2136
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
SearchMssql\getIndexField
getIndexField( $fulltext)
Picks which field to index on, depending on what type of query.
Definition: SearchMssql.php:108
SearchMssql\queryNamespaces
queryNamespaces()
Return a partial WHERE clause to limit the search to the given namespaces.
Definition: SearchMssql.php:59