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) {