From 811f7fb65be6587a5c5cad792b4a87d800a50414 Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Thu, 2 Dec 2004 19:09:40 +0000 Subject: [PATCH] * move SpecialSearch::getSearchEngines() to SearchEngine::create() * add SearchEngine*::update() and updateTitle() * move sql queries from SearchUpdate to SearchEngine* (update and updateTitle() --- includes/SearchEngine.php | 31 +++++++++++++++++++++++++++++-- includes/SearchMySQL3.php | 24 +++++++++++++++++++++++- includes/SearchMySQL4.php | 25 ++++++++++++++++++++++++- includes/SearchUpdate.php | 21 ++++++--------------- includes/SpecialSearch.php | 33 +++------------------------------ 5 files changed, 85 insertions(+), 49 deletions(-) diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index 58b8cf29ab..d4141b81d1 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -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 { } } - -?> diff --git a/includes/SearchMySQL3.php b/includes/SearchMySQL3.php index 02a9332f8c..c8cf8fa998 100644 --- a/includes/SearchMySQL3.php +++ b/includes/SearchMySQL3.php @@ -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 +?> diff --git a/includes/SearchMySQL4.php b/includes/SearchMySQL4.php index 0144576bdb..5e97945504 100644 --- a/includes/SearchMySQL4.php +++ b/includes/SearchMySQL4.php @@ -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 +?> diff --git a/includes/SearchUpdate.php b/includes/SearchUpdate.php index 9337aa2a36..8e0b74f32f 100644 --- a/includes/SearchUpdate.php +++ b/includes/SearchUpdate.php @@ -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 ); } } diff --git a/includes/SpecialSearch.php b/includes/SpecialSearch.php index 95ca38055a..c604313c14 100644 --- a/includes/SpecialSearch.php +++ b/includes/SpecialSearch.php @@ -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 -- 2.20.1