Add a rewind function to SearchResultSet
authorErik Bernhardson <ebernhardson@wikimedia.org>
Wed, 13 Apr 2016 19:21:54 +0000 (12:21 -0700)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Wed, 13 Apr 2016 21:15:31 +0000 (14:15 -0700)
This is implemented in CirrusSearch so the result set can be looped
through multiple times. In general having a rewind function on any
iterator is probably a good idea, so pushing it into the upstream
interface.

Change-Id: Iaac9c11d8742288610011a2a0f6282944d35d5f3

includes/search/SearchNearMatchResultSet.php
includes/search/SearchResultSet.php
includes/search/SqlSearchResultSet.php

index cb4f81d..510726b 100644 (file)
@@ -23,4 +23,8 @@ class SearchNearMatchResultSet extends SearchResultSet {
                $this->fetched = true;
                return SearchResult::newFromTitle( $this->result );
        }
+
+       public function rewind() {
+               $this->fetched = false;
+       }
 }
index bfee698..a673dba 100644 (file)
@@ -154,6 +154,12 @@ class SearchResultSet {
                return false;
        }
 
+       /**
+        * Rewind result set back to begining
+        */
+       function rewind() {
+       }
+
        /**
         * Frees the result set, if applicable.
         */
index 7a6aaf7..6b60899 100644 (file)
@@ -8,7 +8,7 @@ class SqlSearchResultSet extends SearchResultSet {
        protected $terms;
        protected $totalHits;
 
-       function __construct( $resultSet, $terms, $total = null ) {
+       function __construct( ResultWrapper $resultSet, $terms, $total = null ) {
                $this->resultSet = $resultSet;
                $this->terms = $terms;
                $this->totalHits = $total;
@@ -41,6 +41,12 @@ class SqlSearchResultSet extends SearchResultSet {
                );
        }
 
+       function rewind() {
+               if ( $this->resultSet ) {
+                       $this->resultSet->rewind();
+               }
+       }
+
        function free() {
                if ( $this->resultSet === false ) {
                        return false;