From e8ad8d066d4600b7296cccf441981b532e7780f6 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Mon, 18 Aug 2008 15:22:00 +0000 Subject: [PATCH] Remove DB logic from SearchEngine. New method in Database and associated subclasses called getSearchEngine() does this now. --- includes/SearchEngine.php | 13 ++++--------- includes/db/Database.php | 10 ++++++++++ includes/db/DatabaseOracle.php | 4 ++++ includes/db/DatabasePostgres.php | 4 ++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index 916e1fdfbc..cfa560d87b 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -282,19 +282,14 @@ class SearchEngine { * @return SearchEngine */ public static function create() { - global $wgDBtype, $wgSearchType; + global $wgSearchType; + $dbr = wfGetDB( DB_SLAVE ); if( $wgSearchType ) { $class = $wgSearchType; - } elseif( $wgDBtype == 'mysql' ) { - $class = 'SearchMySQL'; - } else if ( $wgDBtype == 'postgres' ) { - $class = 'SearchPostgres'; - } else if ( $wgDBtype == 'oracle' ) { - $class = 'SearchOracle'; } else { - $class = 'SearchEngineDummy'; + $class = $dbr->getSearchEngine(); } - $search = new $class( wfGetDB( DB_SLAVE ) ); + $search = new $class( $dbr ); $search->setLimitOffset(0,0); return $search; } diff --git a/includes/db/Database.php b/includes/db/Database.php index 2e3e0edccd..5b39564958 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2271,6 +2271,16 @@ class Database { $result = $this->query( "SELECT RELEASE_LOCK($lockName)", $method ); $this->freeResult( $result ); } + + /** + * Get search engine class. All subclasses of this + * need to implement this if they wish to use searching. + * + * @return string + */ + public function getSearchEngine() { + return "SearchMySQL"; + } } /** diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index f4dbac71b3..67c8ffffc4 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -716,5 +716,9 @@ echo "error!\n"; public function unlock( $lockName, $method ) { return true; } + + public function getSearchEngine() { + return "SearchOracle"; + } } // end DatabaseOracle class diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 065ad56d56..bf948c9d46 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -1390,5 +1390,9 @@ END; public function unlock( $lockName, $method ) { return true; } + + public function getSearchEngine() { + return "SearchPostgres"; + } } // end DatabasePostgres class -- 2.20.1