Use Solr everywhere to retrieve books
This commit is contained in:
@@ -86,4 +86,34 @@ class BookSearch
|
||||
'books' => $books,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrive books from Solr based on their code (NoticeNr).
|
||||
*
|
||||
* @param array $codes
|
||||
* @param string $field the field to use for the search
|
||||
* @return array Books information
|
||||
* @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);
|
||||
if($count > $limit) {
|
||||
$parts = array_chunk($codes, $limit);
|
||||
$books = array();
|
||||
foreach($parts as $p) {
|
||||
$books = array_merge($books, self::GetBooks($p));
|
||||
}
|
||||
return $books;
|
||||
}
|
||||
|
||||
$bs = new static();
|
||||
$query = sprintf('%s:(%s)', $field, implode(' OR ', $codes));
|
||||
$bs->addQuery($query, null, false);
|
||||
$results = $bs->getResults(0, $count);
|
||||
return $results['books'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user