From 110eb02f3abf910aee0a4ffd5ca9bcc79404176b Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Fri, 17 Jan 2014 16:43:40 -0800 Subject: [PATCH] Begin abstracting more of the database-specific search backend out There's a lot in the base search implementations that is specific to the database backed search. This starts moving some of that out into a shared base class for those. For starters, let's not grab a connection to the slave DB for every single search for backends unless they need it. Change-Id: Ib66696841eea901e04b21dd309784af889a45ab1 --- includes/AutoLoader.php | 1 + includes/search/SearchDatabase.php | 46 ++++++++++++++++++++++++++++++ includes/search/SearchEngine.php | 13 --------- includes/search/SearchMssql.php | 11 +------ includes/search/SearchMySQL.php | 10 +------ includes/search/SearchOracle.php | 10 +------ includes/search/SearchPostgres.php | 15 +--------- includes/search/SearchSqlite.php | 16 +---------- 8 files changed, 52 insertions(+), 70 deletions(-) create mode 100644 includes/search/SearchDatabase.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index bab00f9562..acca9dc2f3 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -884,6 +884,7 @@ $wgAutoloadLocalClasses = array( 'MySQLSearchResultSet' => 'includes/search/SearchMySQL.php', 'PostgresSearchResult' => 'includes/search/SearchPostgres.php', 'PostgresSearchResultSet' => 'includes/search/SearchPostgres.php', + 'SearchDatabase' => 'includes/search/SearchDatabase.php', 'SearchEngine' => 'includes/search/SearchEngine.php', 'SearchEngineDummy' => 'includes/search/SearchEngine.php', 'SearchHighlighter' => 'includes/search/SearchEngine.php', diff --git a/includes/search/SearchDatabase.php b/includes/search/SearchDatabase.php new file mode 100644 index 0000000000..e3aafe8679 --- /dev/null +++ b/includes/search/SearchDatabase.php @@ -0,0 +1,46 @@ +db = $db; + } else { + $this->db = wfGetDB( DB_SLAVE ); + } + } +} diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 9ebe5e7aa0..47f513151c 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -41,19 +41,6 @@ class SearchEngine { /// Feature values protected $features = array(); - /** - * @var DatabaseBase - */ - protected $db; - - function __construct( $db = null ) { - if ( $db ) { - $this->db = $db; - } else { - $this->db = wfGetDB( DB_SLAVE ); - } - } - /** * Perform a full text search query and return a result set. * If title searches are not supported or disabled, return null. diff --git a/includes/search/SearchMssql.php b/includes/search/SearchMssql.php index cbc1a7a7f1..15b5f1ce23 100644 --- a/includes/search/SearchMssql.php +++ b/includes/search/SearchMssql.php @@ -25,16 +25,7 @@ * Search engine hook base class for Mssql (ConText). * @ingroup Search */ -class SearchMssql extends SearchEngine { - - /** - * Creates an instance of this class - * @param $db DatabaseMssql: database object - */ - function __construct( $db ) { - parent::__construct( $db ); - } - +class SearchMssql extends SearchDatabase { /** * Perform a full text search query and return a result set. * diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php index b2bc1c268a..aec6a0197d 100644 --- a/includes/search/SearchMySQL.php +++ b/includes/search/SearchMySQL.php @@ -28,18 +28,10 @@ * Search engine hook for MySQL 4+ * @ingroup Search */ -class SearchMySQL extends SearchEngine { +class SearchMySQL extends SearchDatabase { var $strictMatching = true; static $mMinSearchLength; - /** - * Creates an instance of this class - * @param $db DatabaseMysql: database object - */ - function __construct( $db ) { - parent::__construct( $db ); - } - /** * Parse the user's query and transform it into an SQL fragment which will * become part of a WHERE clause diff --git a/includes/search/SearchOracle.php b/includes/search/SearchOracle.php index a84796542f..cea17d28fc 100644 --- a/includes/search/SearchOracle.php +++ b/includes/search/SearchOracle.php @@ -28,7 +28,7 @@ * Search engine hook base class for Oracle (ConText). * @ingroup Search */ -class SearchOracle extends SearchEngine { +class SearchOracle extends SearchDatabase { private $reservedWords = array( 'ABOUT' => 1, @@ -59,14 +59,6 @@ class SearchOracle extends SearchEngine { 'WITHIN' => 1, ); - /** - * Creates an instance of this class - * @param $db DatabasePostgres: database object - */ - function __construct( $db ) { - parent::__construct( $db ); - } - /** * Perform a full text search query and return a result set. * diff --git a/includes/search/SearchPostgres.php b/includes/search/SearchPostgres.php index 7f19ed13ff..c9f5466d78 100644 --- a/includes/search/SearchPostgres.php +++ b/includes/search/SearchPostgres.php @@ -28,20 +28,7 @@ * Search engine hook base class for Postgres * @ingroup Search */ -class SearchPostgres extends SearchEngine { - - /** - * @var DatabasePostgres - */ - protected $db; - /** - * Creates an instance of this class - * @param $db DatabaseSqlite: database object - */ - function __construct( $db ) { - parent::__construct( $db ); - } - +class SearchPostgres extends SearchDatabase { /** * Perform a full text search query via tsearch2 and return a result set. * Currently searches a page's current title (page.page_title) and diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php index 554181f6e9..ebff68ef1f 100644 --- a/includes/search/SearchSqlite.php +++ b/includes/search/SearchSqlite.php @@ -25,21 +25,7 @@ * Search engine hook for SQLite * @ingroup Search */ -class SearchSqlite extends SearchEngine { - - /** - * @var DatabaseSqlite - */ - protected $db; - - /** - * Creates an instance of this class - * @param $db DatabaseSqlite: database object - */ - function __construct( $db ) { - parent::__construct( $db ); - } - +class SearchSqlite extends SearchDatabase { /** * Whether fulltext search is supported by current schema * @return Boolean -- 2.20.1