fix: not returning all the results
This commit is contained in:
@@ -285,25 +285,25 @@ class BookSearch
|
|||||||
* @throws WebException
|
* @throws WebException
|
||||||
*/
|
*/
|
||||||
public static function getBooks(array $codes, $field = 'code') {
|
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;
|
$limit = 15;
|
||||||
$count = count($codes);
|
|
||||||
|
|
||||||
$bs = self::getLastInstance();
|
$bs = self::getLastInstance();
|
||||||
$parts = $count <= $limit ? [$codes] : array_chunk($codes, $limit);
|
|
||||||
$books = [];
|
$books = [];
|
||||||
foreach($parts as $p) {
|
foreach (array_chunk($codes, $limit) as $chunk) {
|
||||||
// if we use array_merge here the numerical keys (book code) will be lost
|
// Reset query state for this chunk
|
||||||
$bs->addOrQuery($p, $field);
|
$bs->clearQueryParts();
|
||||||
$results = $bs->getResults(0, $count);
|
$bs->addOrQuery($chunk, $field);
|
||||||
$foundBooks = $results['books'];
|
// Use count($chunk) so you only request as many rows as there are codes in this chunk
|
||||||
$books += $foundBooks;
|
$results = $bs->getResults(0, count($chunk));
|
||||||
|
$books += $results['books'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $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
|
* it is faster to do multiple small request to Solr rather than one big so
|
||||||
|
|||||||
Reference in New Issue
Block a user