From: Brion Vibber Date: Tue, 18 Mar 2008 23:50:05 +0000 (+0000) Subject: * (bug 11563) Deprecated SearchMySQL4 class; merged code to SearchMySQL X-Git-Tag: 1.31.0-rc.0~49001 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=850cc98cf0a4ee79d1e35b98f466326d73e7810a;p=lhc%2Fweb%2Fwiklou.git * (bug 11563) Deprecated SearchMySQL4 class; merged code to SearchMySQL Some general cleanup on search backend code style :) --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a4f868b835..166a0de74c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -101,6 +101,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 13265) Media handler is missing 'image/x-bmp' * (bug 13407) MediaWiki:Powersearch is used in two places * (bug 13403) Fix cache invalidation of history pages when old revisions change +* (bug 11563) Deprecated SearchMySQL4 class; merged code to SearchMySQL === API changes in 1.13 === diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index c22e58d722..ff93cdfa25 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -213,7 +213,7 @@ class SearchEngine { if( $wgSearchType ) { $class = $wgSearchType; } elseif( $wgDBtype == 'mysql' ) { - $class = 'SearchMySQL4'; + $class = 'SearchMySQL'; } else if ( $wgDBtype == 'postgres' ) { $class = 'SearchPostgres'; } else if ( $wgDBtype == 'oracle' ) { diff --git a/includes/SearchMySQL.php b/includes/SearchMySQL.php index 905075ef5b..e6e312cbd9 100644 --- a/includes/SearchMySQL.php +++ b/includes/SearchMySQL.php @@ -18,11 +18,59 @@ # http://www.gnu.org/copyleft/gpl.html /** - * Search engine hook base class for MySQL. - * Specific bits for MySQL 3 and 4 variants are in child classes. + * Search engine hook for MySQL 4+ * @addtogroup Search */ class SearchMySQL extends SearchEngine { + var $strictMatching = true; + + /** @todo document */ + function __construct( $db ) { + $this->db = $db; + } + + /** @todo document */ + function parseQuery( $filteredText, $fulltext ) { + global $wgContLang; + $lc = SearchEngine::legalSearchChars(); // Minus format chars + $searchon = ''; + $this->searchTerms = array(); + + # FIXME: This doesn't handle parenthetical expressions. + $m = array(); + if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', + $filteredText, $m, PREG_SET_ORDER ) ) { + foreach( $m as $terms ) { + if( $searchon !== '' ) $searchon .= ' '; + if( $this->strictMatching && ($terms[1] == '') ) { + $terms[1] = '+'; + } + $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] ); + if( !empty( $terms[3] ) ) { + // Match individual terms in result highlighting... + $regexp = preg_quote( $terms[3], '/' ); + if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+"; + } else { + // Match the quoted term in result highlighting... + $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' ); + } + $this->searchTerms[] = "\b$regexp\b"; + } + wfDebug( "Would search with '$searchon'\n" ); + wfDebug( 'Match with /\b' . implode( '\b|\b', $this->searchTerms ) . "\b/\n" ); + } else { + wfDebug( "Can't understand search query '{$filteredText}'\n" ); + } + + $searchon = $this->db->strencode( $searchon ); + $field = $this->getIndexField( $fulltext ); + return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) "; + } + + public static function legalSearchChars() { + return "\"*" . parent::legalSearchChars(); + } + /** * Perform a full text search query and return a result set. * @@ -154,7 +202,7 @@ class SearchMySQL extends SearchEngine { 'si_page' => $id, 'si_title' => $title, 'si_text' => $text - ), 'SearchMySQL4::update' ); + ), __METHOD__ ); } /** @@ -170,7 +218,7 @@ class SearchMySQL extends SearchEngine { $dbw->update( 'searchindex', array( 'si_title' => $title ), array( 'si_page' => $id ), - 'SearchMySQL4::updateTitle', + __METHOD__, array( $dbw->lowPriorityOption() ) ); } } diff --git a/includes/SearchMySQL4.php b/includes/SearchMySQL4.php index 271dbe1da3..dd2c0e814a 100644 --- a/includes/SearchMySQL4.php +++ b/includes/SearchMySQL4.php @@ -19,56 +19,11 @@ /** * Search engine hook for MySQL 4+ + * This class retained for backwards compatibility... + * The meat's been moved to SearchMySQL, since the 3.x variety is gone. * @addtogroup Search + * @deprecated */ class SearchMySQL4 extends SearchMySQL { - var $strictMatching = true; - - /** @todo document */ - function SearchMySQL4( $db ) { - $this->db = $db; - } - - /** @todo document */ - function parseQuery( $filteredText, $fulltext ) { - global $wgContLang; - $lc = SearchEngine::legalSearchChars(); // Minus format chars - $searchon = ''; - $this->searchTerms = array(); - - # FIXME: This doesn't handle parenthetical expressions. - $m = array(); - if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', - $filteredText, $m, PREG_SET_ORDER ) ) { - foreach( $m as $terms ) { - if( $searchon !== '' ) $searchon .= ' '; - if( $this->strictMatching && ($terms[1] == '') ) { - $terms[1] = '+'; - } - $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] ); - if( !empty( $terms[3] ) ) { - // Match individual terms in result highlighting... - $regexp = preg_quote( $terms[3], '/' ); - if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+"; - } else { - // Match the quoted term in result highlighting... - $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' ); - } - $this->searchTerms[] = "\b$regexp\b"; - } - wfDebug( "Would search with '$searchon'\n" ); - wfDebug( 'Match with /\b' . implode( '\b|\b', $this->searchTerms ) . "\b/\n" ); - } else { - wfDebug( "Can't understand search query '{$filteredText}'\n" ); - } - - $searchon = $this->db->strencode( $searchon ); - $field = $this->getIndexField( $fulltext ); - return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) "; - } - - public static function legalSearchChars() { - return "\"*" . parent::legalSearchChars(); - } + /* whee */ } - diff --git a/includes/SearchTsearch2.php b/includes/SearchTsearch2.php index 06eaa72d15..d4c6cee509 100644 --- a/includes/SearchTsearch2.php +++ b/includes/SearchTsearch2.php @@ -29,8 +29,8 @@ class SearchTsearch2 extends SearchEngine { var $strictMatching = false; - function SearchTsearch2( &$db ) { - $this->db =& $db; + function __construct( $db ) { + $this->db = $db; $this->mRanking = true; } @@ -68,14 +68,14 @@ class SearchTsearch2 extends SearchEngine { wfDebug( "Can't understand search query '{$this->filteredText}'\n" ); } - $searchon = preg_replace('/(\s+)/','&',$searchon); + $searchon = preg_replace( '/(\s+)/', '&', $searchon ); $searchon = $this->db->strencode( $searchon ); return $searchon; } - function queryRanking($filteredTerm, $fulltext) { + function queryRanking( $filteredTerm, $fulltext ) { $field = $this->getIndexField( $fulltext ); - $searchon = $this->parseQuery($filteredTerm,$fulltext); + $searchon = $this->parseQuery( $filteredTerm, $fulltext ); if ($this->mRanking) return " ORDER BY rank($field,to_tsquery('$searchon')) DESC"; else @@ -95,16 +95,16 @@ class SearchTsearch2 extends SearchEngine { } function update( $id, $title, $text ) { - $dbw = wfGetDB(DB_MASTER); + $dbw = wfGetDB( DB_MASTER ); $searchindex = $dbw->tableName( 'searchindex' ); $sql = "DELETE FROM $searchindex WHERE si_page={$id}"; - $dbw->query($sql,"SearchTsearch2:update"); + $dbw->query( $sql, __METHOD__ ); $sql = "INSERT INTO $searchindex (si_page,si_title,si_text) ". " VALUES ( $id, to_tsvector('". $dbw->strencode($title). "'),to_tsvector('". $dbw->strencode( $text)."')) "; - $dbw->query($sql,"SearchTsearch2:update"); + $dbw->query($sql, __METHOD__ ); } function updateTitle($id,$title) { @@ -114,7 +114,7 @@ class SearchTsearch2 extends SearchEngine { $dbw->strencode( $title ) . "') WHERE si_page={$id}"; - $dbw->query( $sql, "SearchMySQL4::updateTitle" ); + $dbw->query( $sql, __METHOD__ ); } }