fix: not returning all the results
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user