Merge "Force default search backend on search test"
[lhc/web/wiklou.git] / includes / search / SearchResultSet.php
index 178129a..698f93c 100644 (file)
@@ -40,16 +40,6 @@ class SearchResultSet {
                return 0;
        }
 
-       /**
-        * Return true if results are included in this result set.
-        * STUB
-        *
-        * @return bool
-        */
-       function hasResults() {
-               return false;
-       }
-
        /**
         * Some search modes return a total hit count for the query
         * in the entire article database. This may include pages
@@ -139,32 +129,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 +165,20 @@ class SqlSearchResultSet extends SearchResultSet {
        }
 
        function free() {
-               if ( $this->mResultSet === false ) {
+               if ( $this->resultSet === false ) {
                        return false;
                }
 
-               $this->mResultSet->free();
+               $this->resultSet->free();
+       }
+
+       function getTotalHits() {
+               if ( !is_null( $this->totalHits ) ) {
+                       return $this->totalHits;
+               } else {
+                       // Special:Search expects a number here.
+                       return $this->numRows();
+               }
        }
 }
 
@@ -194,12 +195,8 @@ class SearchNearMatchResultSet extends SearchResultSet {
                $this->result = $match;
        }
 
-       public function hasResult() {
-               return (bool)$this->result;
-       }
-
        public function numRows() {
-               return $this->hasResults() ? 1 : 0;
+               return $this->result ? 1 : 0;
        }
 
        public function next() {