* (bug 11563) Deprecated SearchMySQL4 class; merged code to SearchMySQL
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 18 Mar 2008 23:50:05 +0000 (23:50 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 18 Mar 2008 23:50:05 +0000 (23:50 +0000)
Some general cleanup on search backend code style :)

RELEASE-NOTES
includes/SearchEngine.php
includes/SearchMySQL.php
includes/SearchMySQL4.php
includes/SearchTsearch2.php

index a4f868b..166a0de 100644 (file)
@@ -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 ===
index c22e58d..ff93cdf 100644 (file)
@@ -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' ) {
index 905075e..e6e312c 100644 (file)
 # 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() ) );
        }
 }
index 271dbe1..dd2c0e8 100644 (file)
 
 /**
  * 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 */
 }
-
index 06eaa72..d4c6cee 100644 (file)
@@ -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__ );
        }
 
 }