From 2b5e236550125ca2a6ddec81cbcdae6783662c45 Mon Sep 17 00:00:00 2001 From: Joe Z Date: Tue, 12 Apr 2016 20:39:40 -0400 Subject: [PATCH] reset the internal array to avoid miestorious positional bug --- lib/doofinder_management_api.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/doofinder_management_api.php b/lib/doofinder_management_api.php index 9cae594..cea9bd6 100644 --- a/lib/doofinder_management_api.php +++ b/lib/doofinder_management_api.php @@ -178,14 +178,16 @@ public function getScrolledItemsPage($dType, $scrollId = null) { * It only paginates forward. Can't go backwards * @param string $dType Type of the items to list * @param string $scrollId identifier of the pagination set - * @return array Assoc array with scroll_id and paginated results + * @return array Assoc array with scroll_id ,paginated results and total results. */ $params = $scrollId ? array("scroll_id"=>$scrollId) : null; + $result = $this->dma->managementApiCall( 'GET', $this->hashid.'/items/'.$dType, $params ); + return array( 'scroll_id' => $result['response']['scroll_id'], 'results' => $result['response']['results'], @@ -375,7 +377,7 @@ function __construct($searchEngine, $dType){ } private function fetchResults(){ - $apiResults = $this->searchEngine->getScrolledItemsPage($this->dType); + $apiResults = $this->searchEngine->getScrolledItemsPage($this->dType, $this->scrollId); $this->total = $apiResults['total']; $this->resultsPage = $apiResults['results']; $this->scrollId = $apiResults['scroll_id']; @@ -383,11 +385,11 @@ private function fetchResults(){ } function rewind() { + $this->scrollId = null; $this->fetchResults(); } function valid(){ - print "\nValid? ".$this->position.", ".$this->total; return $this->position < $this->total; } @@ -404,6 +406,7 @@ function next(){ $this->currentItem = each($this->resultsPage); if(!$this->currentItem and $this->position < $this->total){ $this->fetchResults(); + reset($this->resultsPage); $this->currentItem = each($this->resultsPage); } }