From 17fe05776593f89c9c6d65629039aced3a66a8a3 Mon Sep 17 00:00:00 2001 From: Guillermo Pages Date: Fri, 1 Jul 2022 09:26:11 +0200 Subject: [PATCH] fix: returning a list of only count limit when codes count > limit --- src/BookSearch/BookSearch.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/BookSearch/BookSearch.php b/src/BookSearch/BookSearch.php index 51e4d6e..fb75786 100644 --- a/src/BookSearch/BookSearch.php +++ b/src/BookSearch/BookSearch.php @@ -289,21 +289,19 @@ class BookSearch // 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); - if($count > $limit) { - $parts = array_chunk($codes, $limit); - $books = array(); - foreach($parts as $p) { - // if we use array_merge here the numerical keys (book code) will be lost - $books += self::getBooks($p, $field); - } - return $books; - } $bs = self::getLastInstance(); - $bs->addOrQuery($codes, $field); + $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($codes, $field); + $results = $bs->getResults(0, $count); + $foundBooks = $results['books']; + $books += $foundBooks; + } - $results = $bs->getResults(0, $count); - return $results['books']; + return $books; } public static function getTerms($field) {