Begin abstracting more of the database-specific search backend out
authorChad Horohoe <chadh@wikimedia.org>
Sat, 18 Jan 2014 00:43:40 +0000 (16:43 -0800)
committerChad Horohoe <chadh@wikimedia.org>
Wed, 22 Jan 2014 01:53:16 +0000 (17:53 -0800)
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
includes/search/SearchDatabase.php [new file with mode: 0644]
includes/search/SearchEngine.php
includes/search/SearchMssql.php
includes/search/SearchMySQL.php
includes/search/SearchOracle.php
includes/search/SearchPostgres.php
includes/search/SearchSqlite.php

index bab00f9..acca9dc 100644 (file)
@@ -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 (file)
index 0000000..e3aafe8
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Database search engine
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Search
+ */
+
+/**
+ * Base search engine base class for database-backed searches
+ * @ingroup Search
+ * @since 1.23
+ */
+class SearchDatabase extends SearchEngine {
+       /**
+        * @var DatabaseBase Slave database for reading from for results
+        */
+       protected $db;
+
+       /**
+        * Constructor
+        * @param DatabaseBase $db The database to search from
+        */
+       public function __construct( DatabaseBase $db = null ) {
+               if ( $db ) {
+                       $this->db = $db;
+               } else {
+                       $this->db = wfGetDB( DB_SLAVE );
+               }
+       }
+}
index 9ebe5e7..47f5131 100644 (file)
@@ -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.
index cbc1a7a..15b5f1c 100644 (file)
  * 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.
         *
index b2bc1c2..aec6a01 100644 (file)
  * 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
index a847965..cea17d2 100644 (file)
@@ -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.
         *
index 7f19ed1..c9f5466 100644 (file)
  * 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
index 554181f..ebff68e 100644 (file)
  * 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