Clean up database-backed SearchResultSets
authorChad Horohoe <chadh@wikimedia.org>
Tue, 22 Apr 2014 07:52:19 +0000 (00:52 -0700)
committerChad Horohoe <chadh@wikimedia.org>
Tue, 22 Apr 2014 19:56:36 +0000 (12:56 -0700)
SqlSearchResultSet basically handles all of the work in a DB-agnostic
manner. Remove specific implementations for MySQL, Mssql and Sqlite

Change-Id: Iae3fd5cc40dfbc50917be73d7ace668681e4148a

includes/AutoLoader.php
includes/search/SearchMssql.php
includes/search/SearchMySQL.php
includes/search/SearchOracle.php
includes/search/SearchPostgres.php
includes/search/SearchResultSet.php
includes/search/SearchSqlite.php

index 077c72c..5545767 100644 (file)
@@ -887,8 +887,6 @@ $wgAutoloadLocalClasses = array(
        'RevisionDeleteUser' => 'includes/revisiondelete/RevisionDeleteUser.php',
 
        # includes/search
-       'MssqlSearchResultSet' => 'includes/search/SearchMssql.php',
-       'MySQLSearchResultSet' => 'includes/search/SearchMySQL.php',
        'PostgresSearchResult' => 'includes/search/SearchPostgres.php',
        'PostgresSearchResultSet' => 'includes/search/SearchPostgres.php',
        'SearchDatabase' => 'includes/search/SearchDatabase.php',
@@ -904,7 +902,6 @@ $wgAutoloadLocalClasses = array(
        'SearchResultSet' => 'includes/search/SearchResultSet.php',
        'SearchResultTooMany' => 'includes/search/SearchEngine.php',
        'SearchSqlite' => 'includes/search/SearchSqlite.php',
-       'SqliteSearchResultSet' => 'includes/search/SearchSqlite.php',
        'SqlSearchResultSet' => 'includes/search/SearchResultSet.php',
 
        # includes/site
index 6326112..3eef498 100644 (file)
@@ -30,24 +30,24 @@ class SearchMssql extends SearchDatabase {
         * Perform a full text search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return MssqlSearchResultSet
+        * @return SqlSearchResultSet
         * @access public
         */
        function searchText( $term ) {
                $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), true ) ) );
-               return new MssqlSearchResultSet( $resultSet, $this->searchTerms );
+               return new SqlSearchResultSet( $resultSet, $this->searchTerms );
        }
 
        /**
         * Perform a title-only search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return MssqlSearchResultSet
+        * @return SqlSearchResultSet
         * @access public
         */
        function searchTitle( $term ) {
                $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
-               return new MssqlSearchResultSet( $resultSet, $this->searchTerms );
+               return new SqlSearchResultSet( $resultSet, $this->searchTerms );
        }
 
        /**
@@ -204,29 +204,3 @@ class SearchMssql extends SearchDatabase {
                return $this->db->query( $sql, 'SearchMssql::updateTitle' );
        }
 }
-
-/**
- * @ingroup Search
- */
-class MssqlSearchResultSet extends SearchResultSet {
-       function __construct( $resultSet, $terms ) {
-               $this->mResultSet = $resultSet;
-               $this->mTerms = $terms;
-       }
-
-       function termMatches() {
-               return $this->mTerms;
-       }
-
-       function numRows() {
-               return $this->mResultSet->numRows();
-       }
-
-       function next() {
-               $row = $this->mResultSet->fetchObject();
-               if ( $row === false ) {
-                       return false;
-               }
-               return new SearchResult( $row );
-       }
-}
index cfe4c29..345ced5 100644 (file)
@@ -153,7 +153,7 @@ class SearchMySQL extends SearchDatabase {
         * Perform a full text search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return MySQLSearchResultSet
+        * @return SqlSearchResultSet
         */
        function searchText( $term ) {
                return $this->searchInternal( $term, true );
@@ -163,7 +163,7 @@ class SearchMySQL extends SearchDatabase {
         * Perform a title-only search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return MySQLSearchResultSet
+        * @return SqlSearchResultSet
         */
        function searchTitle( $term ) {
                return $this->searchInternal( $term, false );
@@ -199,7 +199,7 @@ class SearchMySQL extends SearchDatabase {
                        $totalResult->free();
                }
 
-               return new MySQLSearchResultSet( $resultSet, $this->searchTerms, $total );
+               return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total );
        }
 
        public function supports( $feature ) {
@@ -452,17 +452,3 @@ class SearchMySQL extends SearchDatabase {
                return self::$mMinSearchLength;
        }
 }
-
-/**
- * @ingroup Search
- */
-class MySQLSearchResultSet extends SqlSearchResultSet {
-       function __construct( $resultSet, $terms, $totalHits = null ) {
-               parent::__construct( $resultSet, $terms );
-               $this->mTotalHits = $totalHits;
-       }
-
-       function getTotalHits() {
-               return $this->mTotalHits;
-       }
-}
index d5a6597..93427d1 100644 (file)
@@ -86,7 +86,7 @@ class SearchOracle extends SearchDatabase {
                }
 
                $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
-               return new MySQLSearchResultSet( $resultSet, $this->searchTerms );
+               return new SqlSearchResultSet( $resultSet, $this->searchTerms );
        }
 
        /**
index 2a20d70..42b67f3 100644 (file)
@@ -222,12 +222,8 @@ class PostgresSearchResult extends SearchResult {
  * @ingroup Search
  */
 class PostgresSearchResultSet extends SqlSearchResultSet {
-       function __construct( $resultSet, $terms ) {
-               parent::__construct( $resultSet, $terms );
-       }
-
        function next() {
-               $row = $this->mResultSet->fetchObject();
+               $row = $this->resultSet->fetchObject();
                if ( $row === false ) {
                        return false;
                } else {
index 178129a..f753e3d 100644 (file)
@@ -139,32 +139,34 @@ class SearchResultSet {
  * @ingroup Search
  */
 class SqlSearchResultSet extends SearchResultSet {
+       protected $resultSet;
+       protected $terms;
+       protected $totalHits;
 
-       protected $mResultSet;
-
-       function __construct( $resultSet, $terms ) {
-               $this->mResultSet = $resultSet;
-               $this->mTerms = $terms;
+       function __construct( $resultSet, $terms, $total = null ) {
+               $this->resultSet = $resultSet;
+               $this->terms = $terms;
+               $this->totalHits = $total;
        }
 
        function termMatches() {
-               return $this->mTerms;
+               return $this->terms;
        }
 
        function numRows() {
-               if ( $this->mResultSet === false ) {
+               if ( $this->resultSet === false ) {
                        return false;
                }
 
-               return $this->mResultSet->numRows();
+               return $this->resultSet->numRows();
        }
 
        function next() {
-               if ( $this->mResultSet === false ) {
+               if ( $this->resultSet === false ) {
                        return false;
                }
 
-               $row = $this->mResultSet->fetchObject();
+               $row = $this->resultSet->fetchObject();
                if ( $row === false ) {
                        return false;
                }
@@ -173,11 +175,15 @@ class SqlSearchResultSet extends SearchResultSet {
        }
 
        function free() {
-               if ( $this->mResultSet === false ) {
+               if ( $this->resultSet === false ) {
                        return false;
                }
 
-               $this->mResultSet->free();
+               $this->resultSet->free();
+       }
+
+       function getTotalHits() {
+               return $this->totalHits;
        }
 }
 
index 1a05ee2..1ac4946 100644 (file)
@@ -145,7 +145,7 @@ class SearchSqlite extends SearchDatabase {
         * Perform a full text search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return SqliteSearchResultSet
+        * @return SqlSearchResultSet
         */
        function searchText( $term ) {
                return $this->searchInternal( $term, true );
@@ -155,7 +155,7 @@ class SearchSqlite extends SearchDatabase {
         * Perform a title-only search query and return a result set.
         *
         * @param string $term Raw search term
-        * @return SqliteSearchResultSet
+        * @return SqlSearchResultSet
         */
        function searchTitle( $term ) {
                return $this->searchInternal( $term, false );
@@ -181,7 +181,7 @@ class SearchSqlite extends SearchDatabase {
                        $totalResult->free();
                }
 
-               return new SqliteSearchResultSet( $resultSet, $this->searchTerms, $total );
+               return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total );
        }
 
        /**
@@ -303,17 +303,3 @@ class SearchSqlite extends SearchDatabase {
                        __METHOD__ );
        }
 }
-
-/**
- * @ingroup Search
- */
-class SqliteSearchResultSet extends SqlSearchResultSet {
-       function __construct( $resultSet, $terms, $totalHits = null ) {
-               parent::__construct( $resultSet, $terms );
-               $this->mTotalHits = $totalHits;
-       }
-
-       function getTotalHits() {
-               return $this->mTotalHits;
-       }
-}