diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
commit | 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch) | |
tree | af68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /includes/search/SearchMySQL.php | |
parent | af4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff) |
Update to MediaWiki 1.22.0
Diffstat (limited to 'includes/search/SearchMySQL.php')
-rw-r--r-- | includes/search/SearchMySQL.php | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php index 4a501fd0..b2bc1c26 100644 --- a/includes/search/SearchMySQL.php +++ b/includes/search/SearchMySQL.php @@ -57,12 +57,12 @@ class SearchMySQL extends SearchEngine { # @todo FIXME: This doesn't handle parenthetical expressions. $m = array(); - if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', + if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $filteredText, $m, PREG_SET_ORDER ) ) { - foreach( $m as $bits ) { + foreach ( $m as $bits ) { @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits; - if( $nonQuoted != '' ) { + if ( $nonQuoted != '' ) { $term = $nonQuoted; $quote = ''; } else { @@ -70,8 +70,10 @@ class SearchMySQL extends SearchEngine { $quote = '"'; } - if( $searchon !== '' ) $searchon .= ' '; - if( $this->strictMatching && ($modifier == '') ) { + if ( $searchon !== '' ) { + $searchon .= ' '; + } + if ( $this->strictMatching && ( $modifier == '' ) ) { // If we leave this out, boolean op defaults to OR which is rarely helpful. $modifier = '+'; } @@ -79,7 +81,7 @@ class SearchMySQL extends SearchEngine { // Some languages such as Serbian store the input form in the search index, // so we may need to search for matches in multiple writing system variants. $convertedVariants = $wgContLang->autoConvertToAllVariants( $term ); - if( is_array( $convertedVariants ) ) { + if ( is_array( $convertedVariants ) ) { $variants = array_unique( array_values( $convertedVariants ) ); } else { $variants = array( $term ); @@ -99,11 +101,12 @@ class SearchMySQL extends SearchEngine { $strippedVariants = array_unique( $strippedVariants ); $searchon .= $modifier; - if( count( $strippedVariants) > 1 ) + if ( count( $strippedVariants ) > 1 ) { $searchon .= '('; - foreach( $strippedVariants as $stripped ) { + } + foreach ( $strippedVariants as $stripped ) { $stripped = $this->normalizeText( $stripped ); - if( $nonQuoted && strpos( $stripped, ' ' ) !== false ) { + if ( $nonQuoted && strpos( $stripped, ' ' ) !== false ) { // Hack for Chinese: we need to toss in quotes for // multiple-character phrases since normalizeForSearch() // added spaces between them to make word breaks. @@ -111,8 +114,9 @@ class SearchMySQL extends SearchEngine { } $searchon .= "$quote$stripped$quote$wildcard "; } - if( count( $strippedVariants) > 1 ) + if ( count( $strippedVariants ) > 1 ) { $searchon .= ')'; + } // Match individual terms or quoted phrase in result highlighting... // Note that variants will be introduced in a later stage for highlighting! @@ -134,8 +138,8 @@ class SearchMySQL extends SearchEngine { global $wgContLang; $regex = preg_quote( $string, '/' ); - if( $wgContLang->hasWordBreaks() ) { - if( $wildcard ) { + if ( $wgContLang->hasWordBreaks() ) { + if ( $wildcard ) { // Don't cut off the final bit! $regex = "\b$regex"; } else { @@ -177,7 +181,9 @@ class SearchMySQL extends SearchEngine { global $wgCountTotalSearchHits; // This seems out of place, why is this called with empty term? - if ( trim( $term ) === '' ) return null; + if ( trim( $term ) === '' ) { + return null; + } $filteredTerm = $this->filter( $term ); $query = $this->getQuery( $filteredTerm, $fulltext ); @@ -187,7 +193,7 @@ class SearchMySQL extends SearchEngine { ); $total = null; - if( $wgCountTotalSearchHits ) { + if ( $wgCountTotalSearchHits ) { $query = $this->getCountQuery( $filteredTerm, $fulltext ); $totalResult = $this->db->select( $query['tables'], $query['fields'], $query['conds'], @@ -195,7 +201,7 @@ class SearchMySQL extends SearchEngine { ); $row = $totalResult->fetchObject(); - if( $row ) { + if ( $row ) { $total = intval( $row->c ); } $totalResult->free(); @@ -205,12 +211,11 @@ class SearchMySQL extends SearchEngine { } public function supports( $feature ) { - switch( $feature ) { - case 'list-redirects': + switch ( $feature ) { case 'title-suffix-filter': return true; default: - return false; + return parent::supports( $feature ); } } @@ -223,7 +228,7 @@ class SearchMySQL extends SearchEngine { foreach ( $this->features as $feature => $value ) { if ( $feature === 'list-redirects' && !$value ) { $query['conds']['page_is_redirect'] = 0; - } elseif( $feature === 'title-suffix-filter' && $value ) { + } elseif ( $feature === 'title-suffix-filter' && $value ) { $query['conds'][] = 'page_title' . $this->db->buildLike( $this->db->anyString(), $value ); } } @@ -358,12 +363,25 @@ class SearchMySQL extends SearchEngine { $dbw->update( 'searchindex', array( 'si_title' => $this->normalizeText( $title ) ), - array( 'si_page' => $id ), + array( 'si_page' => $id ), __METHOD__, array( $dbw->lowPriorityOption() ) ); } /** + * 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 + */ + function delete( $id, $title ) { + $dbw = wfGetDB( DB_MASTER ); + + $dbw->delete( 'searchindex', array( 'si_page' => $id ), __METHOD__ ); + } + + /** * Converts some characters for MySQL's indexing to grok it correctly, * and pads short words to overcome limitations. * @return mixed|string @@ -386,7 +404,7 @@ class SearchMySQL extends SearchEngine { // ignores short words... Pad them so we can pass them // through without reconfiguring the server... $minLength = $this->minSearchLength(); - if( $minLength > 1 ) { + if ( $minLength > 1 ) { $n = $minLength - 1; $out = preg_replace( "/\b(\w{1,$n})\b/", @@ -427,7 +445,7 @@ class SearchMySQL extends SearchEngine { * @return int */ protected function minSearchLength() { - if( is_null( self::$mMinSearchLength ) ) { + if ( is_null( self::$mMinSearchLength ) ) { $sql = "SHOW GLOBAL VARIABLES LIKE 'ft\\_min\\_word\\_len'"; $dbr = wfGetDB( DB_SLAVE ); @@ -435,7 +453,7 @@ class SearchMySQL extends SearchEngine { $row = $result->fetchObject(); $result->free(); - if( $row && $row->Variable_name == 'ft_min_word_len' ) { + if ( $row && $row->Variable_name == 'ft_min_word_len' ) { self::$mMinSearchLength = intval( $row->Value ); } else { self::$mMinSearchLength = 0; @@ -449,7 +467,7 @@ class SearchMySQL extends SearchEngine { * @ingroup Search */ class MySQLSearchResultSet extends SqlSearchResultSet { - function __construct( $resultSet, $terms, $totalHits=null ) { + function __construct( $resultSet, $terms, $totalHits = null ) { parent::__construct( $resultSet, $terms ); $this->mTotalHits = $totalHits; } |