From 3c896ec409fd52accd6ed7cd65fcec2521966839 Mon Sep 17 00:00:00 2001 From: Guillermo Pages Date: Thu, 20 Feb 2025 17:05:36 +0100 Subject: [PATCH] fix: not returning all the results --- src/BookSearch/BookSearch.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/BookSearch/BookSearch.php b/src/BookSearch/BookSearch.php index fed3e00..1e22096 100644 --- a/src/BookSearch/BookSearch.php +++ b/src/BookSearch/BookSearch.php @@ -285,25 +285,25 @@ class BookSearch * @throws WebException */ public static function getBooks(array $codes, $field = 'code') { - // it is faster to do multiple small request to Solr rather than one big so separate - // in chunks if we are above the limit. 15 was found by testing and seems to be a sweet spot $limit = 15; - $count = count($codes); - $bs = self::getLastInstance(); - $parts = $count <= $limit ? [$codes] : array_chunk($codes, $limit); $books = []; - foreach($parts as $p) { - // if we use array_merge here the numerical keys (book code) will be lost - $bs->addOrQuery($p, $field); - $results = $bs->getResults(0, $count); - $foundBooks = $results['books']; - $books += $foundBooks; + foreach (array_chunk($codes, $limit) as $chunk) { + // Reset query state for this chunk + $bs->clearQueryParts(); + $bs->addOrQuery($chunk, $field); + // Use count($chunk) so you only request as many rows as there are codes in this chunk + $results = $bs->getResults(0, count($chunk)); + $books += $results['books']; } - return $books; } + public function clearQueryParts(): void { + $this->queryParts = []; + $this->filterQueryParts = []; + } + /** * * it is faster to do multiple small request to Solr rather than one big so