From 15483b22d7d504e3c22cfc832296d52f5c6ad340 Mon Sep 17 00:00:00 2001 From: Erik Bernhardson Date: Wed, 13 Apr 2016 12:21:54 -0700 Subject: [PATCH] Add a rewind function to SearchResultSet 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 | 4 ++++ includes/search/SearchResultSet.php | 6 ++++++ includes/search/SqlSearchResultSet.php | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/search/SearchNearMatchResultSet.php b/includes/search/SearchNearMatchResultSet.php index cb4f81d8b8..510726baaa 100644 --- a/includes/search/SearchNearMatchResultSet.php +++ b/includes/search/SearchNearMatchResultSet.php @@ -23,4 +23,8 @@ class SearchNearMatchResultSet extends SearchResultSet { $this->fetched = true; return SearchResult::newFromTitle( $this->result ); } + + public function rewind() { + $this->fetched = false; + } } diff --git a/includes/search/SearchResultSet.php b/includes/search/SearchResultSet.php index bfee698f12..a673dba486 100644 --- a/includes/search/SearchResultSet.php +++ b/includes/search/SearchResultSet.php @@ -154,6 +154,12 @@ class SearchResultSet { return false; } + /** + * Rewind result set back to begining + */ + function rewind() { + } + /** * Frees the result set, if applicable. */ diff --git a/includes/search/SqlSearchResultSet.php b/includes/search/SqlSearchResultSet.php index 7a6aaf75f0..6b60899f10 100644 --- a/includes/search/SqlSearchResultSet.php +++ b/includes/search/SqlSearchResultSet.php @@ -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; -- 2.20.1