diff options
Diffstat (limited to 'includes/search/SearchMySQL.php')
-rw-r--r-- | includes/search/SearchMySQL.php | 122 |
1 files changed, 51 insertions, 71 deletions
diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php index b2bc1c26..78eba2d0 100644 --- a/includes/search/SearchMySQL.php +++ b/includes/search/SearchMySQL.php @@ -3,7 +3,7 @@ * MySQL search engine * * Copyright (C) 2004 Brion Vibber <brion@pobox.com> - * http://www.mediawiki.org/ + * https://www.mediawiki.org/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,30 +28,24 @@ * Search engine hook for MySQL 4+ * @ingroup Search */ -class SearchMySQL extends SearchEngine { - var $strictMatching = true; - static $mMinSearchLength; +class SearchMySQL extends SearchDatabase { + protected $strictMatching = true; - /** - * Creates an instance of this class - * @param $db DatabaseMysql: database object - */ - function __construct( $db ) { - parent::__construct( $db ); - } + private static $mMinSearchLength; /** * Parse the user's query and transform it into an SQL fragment which will * become part of a WHERE clause * - * @param $filteredText string - * @param $fulltext string + * @param string $filteredText + * @param string $fulltext * * @return string */ function parseQuery( $filteredText, $fulltext ) { global $wgContLang; - $lc = SearchEngine::legalSearchChars(); // Minus format chars + + $lc = $this->legalSearchChars(); // Minus format chars $searchon = ''; $this->searchTerms = array(); @@ -60,7 +54,9 @@ class SearchMySQL extends SearchEngine { if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $filteredText, $m, PREG_SET_ORDER ) ) { foreach ( $m as $bits ) { - @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits; + wfSuppressWarnings(); + list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits; + wfRestoreWarnings(); if ( $nonQuoted != '' ) { $term = $nonQuoted; @@ -129,9 +125,9 @@ class SearchMySQL extends SearchEngine { wfDebug( __METHOD__ . ": Can't understand search query '{$filteredText}'\n" ); } - $searchon = $this->db->strencode( $searchon ); + $searchon = $this->db->addQuotes( $searchon ); $field = $this->getIndexField( $fulltext ); - return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) "; + return " MATCH($field) AGAINST($searchon IN BOOLEAN MODE) "; } function regexTerm( $string, $wildcard ) { @@ -160,8 +156,8 @@ class SearchMySQL extends SearchEngine { /** * Perform a full text search query and return a result set. * - * @param string $term raw search term - * @return MySQLSearchResultSet + * @param string $term Raw search term + * @return SqlSearchResultSet */ function searchText( $term ) { return $this->searchInternal( $term, true ); @@ -170,16 +166,14 @@ class SearchMySQL extends SearchEngine { /** * Perform a title-only search query and return a result set. * - * @param string $term raw search term - * @return MySQLSearchResultSet + * @param string $term Raw search term + * @return SqlSearchResultSet */ function searchTitle( $term ) { return $this->searchInternal( $term, false ); } protected function searchInternal( $term, $fulltext ) { - global $wgCountTotalSearchHits; - // This seems out of place, why is this called with empty term? if ( trim( $term ) === '' ) { return null; @@ -193,21 +187,19 @@ class SearchMySQL extends SearchEngine { ); $total = null; - if ( $wgCountTotalSearchHits ) { - $query = $this->getCountQuery( $filteredTerm, $fulltext ); - $totalResult = $this->db->select( - $query['tables'], $query['fields'], $query['conds'], - __METHOD__, $query['options'], $query['joins'] - ); - - $row = $totalResult->fetchObject(); - if ( $row ) { - $total = intval( $row->c ); - } - $totalResult->free(); + $query = $this->getCountQuery( $filteredTerm, $fulltext ); + $totalResult = $this->db->select( + $query['tables'], $query['fields'], $query['conds'], + __METHOD__, $query['options'], $query['joins'] + ); + + $row = $totalResult->fetchObject(); + if ( $row ) { + $total = intval( $row->c ); } + $totalResult->free(); - return new MySQLSearchResultSet( $resultSet, $this->searchTerms, $total ); + return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total ); } public function supports( $feature ) { @@ -221,14 +213,12 @@ class SearchMySQL extends SearchEngine { /** * Add special conditions - * @param $query Array + * @param array $query * @since 1.18 */ protected function queryFeatures( &$query ) { foreach ( $this->features as $feature => $value ) { - if ( $feature === 'list-redirects' && !$value ) { - $query['conds']['page_is_redirect'] = 0; - } elseif ( $feature === 'title-suffix-filter' && $value ) { + if ( $feature === 'title-suffix-filter' && $value ) { $query['conds'][] = 'page_title' . $this->db->buildLike( $this->db->anyString(), $value ); } } @@ -236,7 +226,7 @@ class SearchMySQL extends SearchEngine { /** * Add namespace conditions - * @param $query Array + * @param array $query * @since 1.18 (changed) */ function queryNamespaces( &$query ) { @@ -250,7 +240,7 @@ class SearchMySQL extends SearchEngine { /** * Add limit options - * @param $query Array + * @param array $query * @since 1.18 */ protected function limitResult( &$query ) { @@ -261,9 +251,9 @@ class SearchMySQL extends SearchEngine { /** * Construct the SQL query to do the search. * The guts shoulds be constructed in queryMain() - * @param $filteredTerm String - * @param $fulltext Boolean - * @return Array + * @param string $filteredTerm + * @param bool $fulltext + * @return array * @since 1.18 (changed) */ function getQuery( $filteredTerm, $fulltext ) { @@ -285,8 +275,8 @@ class SearchMySQL extends SearchEngine { /** * Picks which field to index on, depending on what type of query. - * @param $fulltext Boolean - * @return String + * @param bool $fulltext + * @return string */ function getIndexField( $fulltext ) { return $fulltext ? 'si_text' : 'si_title'; @@ -295,9 +285,9 @@ class SearchMySQL extends SearchEngine { /** * Get the base part of the search query. * - * @param &$query array Search query array - * @param $filteredTerm String - * @param $fulltext Boolean + * @param array &$query Search query array + * @param string $filteredTerm + * @param bool $fulltext * @since 1.18 (changed) */ function queryMain( &$query, $filteredTerm, $fulltext ) { @@ -313,6 +303,8 @@ class SearchMySQL extends SearchEngine { /** * @since 1.18 (changed) + * @param string $filteredTerm + * @param bool $fulltext * @return array */ function getCountQuery( $filteredTerm, $fulltext ) { @@ -336,9 +328,9 @@ class SearchMySQL extends SearchEngine { * Create or update the search index record for the given page. * Title and text should be pre-processed. * - * @param $id Integer - * @param $title String - * @param $text String + * @param int $id + * @param string $title + * @param string $text */ function update( $id, $title, $text ) { $dbw = wfGetDB( DB_MASTER ); @@ -355,8 +347,8 @@ class SearchMySQL extends SearchEngine { * Update a search index record's title only. * Title should be pre-processed. * - * @param $id Integer - * @param $title String + * @param int $id + * @param string $title */ function updateTitle( $id, $title ) { $dbw = wfGetDB( DB_MASTER ); @@ -372,8 +364,8 @@ class SearchMySQL extends SearchEngine { * Delete an indexed page * Title should be pre-processed. * - * @param Integer $id Page id that was deleted - * @param String $title Title of page that was deleted + * @param int $id Page id that was deleted + * @param string $title Title of page that was deleted */ function delete( $id, $title ) { $dbw = wfGetDB( DB_MASTER ); @@ -384,6 +376,7 @@ class SearchMySQL extends SearchEngine { /** * Converts some characters for MySQL's indexing to grok it correctly, * and pads short words to overcome limitations. + * @param string $string * @return mixed|string */ function normalizeText( $string ) { @@ -432,6 +425,7 @@ class SearchMySQL extends SearchEngine { * Armor a case-folded UTF-8 string to get through MySQL's * fulltext search without being mucked up by funny charset * settings or anything else of the sort. + * @param array $matches * @return string */ protected function stripForSearchCallback( $matches ) { @@ -462,17 +456,3 @@ class SearchMySQL extends SearchEngine { return self::$mMinSearchLength; } } - -/** - * @ingroup Search - */ -class MySQLSearchResultSet extends SqlSearchResultSet { - function __construct( $resultSet, $terms, $totalHits = null ) { - parent::__construct( $resultSet, $terms ); - $this->mTotalHits = $totalHits; - } - - function getTotalHits() { - return $this->mTotalHits; - } -} |