* move SpecialSearch::getSearchEngines() to SearchEngine::create()
authorDomas Mituzas <midom@users.mediawiki.org>
Thu, 2 Dec 2004 19:09:40 +0000 (19:09 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Thu, 2 Dec 2004 19:09:40 +0000 (19:09 +0000)
* add SearchEngine*::update() and updateTitle()
* move sql queries from SearchUpdate to SearchEngine* (update and updateTitle()

includes/SearchEngine.php
includes/SearchMySQL3.php
includes/SearchMySQL4.php
includes/SearchUpdate.php
includes/SpecialSearch.php

index 58b8cf2..d4141b8 100644 (file)
@@ -195,6 +195,35 @@ class SearchEngine {
                        $this->queryNamespaces() . ' ' .
                        $this->queryLimit();
        }
+
+       /**
+        * Load up the appropriate search engine class for the currently
+          * active database backend, and return a configured instance.
+          *
+          * @return SearchEngine
+          * @access private
+       */
+       function create() {
+                global $wgDBtype, $wgDBmysql4, $wgSearchType;
+                if( $wgDBtype == 'mysql' ) {
+                        if( $wgDBmysql4 ) {
+                                $class = 'SearchMySQL4';
+                                require_once( 'SearchMySQL4.php' );
+                        } else {
+                                $class = 'SearchMysql3';
+                                require_once( 'SearchMySQL3.php' );
+                        }
+                } else if ( $wgDBtype == 'PostgreSQL' ) {
+                        $class = 'SearchTsearch2';
+                        require_once( 'SearchTsearch2.php' );
+                } else {
+                        $class = 'SearchEngineDummy';
+                }
+                $search = new $class( wfGetDB( DB_SLAVE ) );
+                $search->setLimitOffset(0,0);
+                return $search;
+       }
+
        
 }
 
@@ -205,5 +234,3 @@ class SearchEngineDummy {
        }
 }
 
-
-?>
index 02a9332..c8cf8fa 100644 (file)
@@ -81,6 +81,28 @@ class SearchMySQL3 extends SearchEngine {
                        "FROM $cur,$searchindex " .
                        'WHERE cur_id=si_page AND ' . $match;
        }
+
+       function update( $id, $title, $text ) {
+               $dbw=& wfGetDB(DB_MASTER);
+                $dbw->replace( 'searchindex', array(array('si_page')),
+                        array(
+                                'si_page' => $id,
+                                'si_title' => $dbw->strencode($title),
+                                'si_text' => $dbw->strencode( $text )
+                        ), 'SearchMySQL3::update' );
+       }
+
+       function updateTitle($id,$title) {
+               $dbw=& wfGetDB(DB_MASTER);
+               $lowpri=$dbw->lowPriorityOption();
+               $searchindex = $dbw->tableName( 'searchindex' );
+
+               $sql = "UPDATE $lowpri $searchindex SET si_title='" .
+                          $db->strencode( $title ) .
+                          "' WHERE si_page={$id}";
+
+               $dbw->query( $sql, "SearchMySQL3::updateTitle" );
+       }
 }
 
-?>
\ No newline at end of file
+?>
index 0144576..5e97945 100644 (file)
@@ -78,6 +78,29 @@ class SearchMySQL4 extends SearchEngine {
                        "FROM $cur,$searchindex " .
                        'WHERE cur_id=si_page AND ' . $match;
        }
+
+        function update( $id, $title, $text ) {
+                $dbw=& wfGetDB(DB_MASTER);
+                $dbw->replace( 'searchindex', array(array('si_page')),
+                        array(
+                                'si_page' => $id,
+                                'si_title' => $dbw->strencode($title),
+                                'si_text' => $dbw->strencode( $text )
+                        ), 'SearchMySQL4::update' );
+        }
+
+        function updateTitle($id,$title) {
+                $dbw=& wfGetDB(DB_MASTER);
+                $lowpri=$dbw->lowPriorityOption();
+                $searchindex = $dbw->tableName( 'searchindex' );
+
+                $sql = "UPDATE $lowpri $searchindex SET si_title='" .
+                          $db->strencode( $title ) .
+                          "' WHERE si_page={$id}";
+
+                $dbw->query( $sql, "SearchMySQL4::updateTitle" );
+        }
+
 }
 
-?>
\ No newline at end of file
+?>
index 9337aa2..8e0b74f 100644 (file)
@@ -38,17 +38,12 @@ class SearchUpdate {
                wfProfileIn( $fname );
 
                require_once( 'SearchEngine.php' );
-               $lc = SearchEngine::legalSearchChars() . '&#;';
-               $db =& wfGetDB( DB_MASTER );
-               $searchindex = $db->tableName( 'searchindex' );
+               $search =& SearchEngine::create();
+               $lc = $search->legalSearchChars() . '&#;';
                
                if( $this->mText == false ) {
-                       # Just update the title
-                       $lowpri = $db->lowPriorityOption();
-                       $sql = "UPDATE $lowpri $searchindex SET si_title='" .
-                         $db->strencode( Title::indexTitle( $this->mNamespace, $this->mTitle ) ) .
-                         "' WHERE si_page={$this->mId}";
-                       $db->query( $sql, "SearchUpdate::doUpdate" );
+                       $search->updateTitle($this->mId,
+                               Title::indexTitle( $this->mNamespace, $this->mTitle ));
                        wfProfileOut( $fname );
                        return;
                }
@@ -104,12 +99,8 @@ class SearchUpdate {
                # Strip wiki '' and '''
                $text = preg_replace( "/''[']*/", " ", $text );
                wfProfileOut( "$fname-regexps" );
-               $db->replace( 'searchindex', array(array('si_page')),
-                       array(
-                               'si_page' => $this->mId,
-                               'si_title' => $db->strencode( Title::indexTitle( $this->mNamespace, $this->mTitle ) ),
-                               'si_text' => $db->strencode( $text )
-                       ), 'SearchUpdate::doUpdate' );
+               $search->update($this->mId, Title::indexTitle( $this->mNamespace, $this->mTitle ),
+                               $text);
                wfProfileOut( $fname );
        }
 }
index 95ca380..c604313 100644 (file)
@@ -141,7 +141,9 @@ class SpecialSearch {
                        return;
                }
 
-               $search =& $this->getSearchEngine();
+               $search =& SearchEngine::create();
+               $search->setLimitOffset( $this->limit, $this->offset );
+               $search->setNamespaces( $this->namespaces );
                $titleMatches = $search->searchTitle( $term );
                $textMatches = $search->searchText( $term );
                
@@ -204,35 +206,6 @@ class SpecialSearch {
                $wgOut->setArticleRelated( false );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
        }
-
-       /**
-        * Load up the appropriate search engine class for the currently
-        * active database backend, and return a configured instance.
-        *
-        * @return SearchEngine
-        * @access private
-        */
-       function &getSearchEngine() {
-               global $wgDBtype, $wgDBmysql4, $wgSearchType;
-               if( $wgDBtype == 'mysql' ) {
-                       if( $wgDBmysql4 ) {
-                               $class = 'SearchMySQL4';
-                               require_once( 'SearchMySQL4.php' );
-                       } else {
-                               $class = 'SearchMysql3';
-                               require_once( 'SearchMySQL3.php' );
-                       }
-               } else if ( $wgDBtype == 'PostgreSQL' ) {
-                       $class = 'SearchTsearch2';
-                       require_once( 'SearchTsearch2.php' );
-               } else {
-                       $class = 'SearchEngineDummy';
-               }
-               $search = new $class( wfGetDB( DB_SLAVE ) );
-               $search->setLimitOffset( $this->limit, $this->offset );
-               $search->setNamespaces( $this->namespaces );
-               return $search;
-       }
        
        /**
         * Extract default namespaces to search from the given user's