move getting books by chung to base function
This commit is contained in:
@@ -64,6 +64,19 @@ class NetBiblio extends WebService
|
|||||||
* @throws WebException
|
* @throws WebException
|
||||||
*/
|
*/
|
||||||
private function GetBooks(array $codes) {
|
private function GetBooks(array $codes) {
|
||||||
|
// 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($codes) > $limit) {
|
||||||
|
$parts = array_chunk($codes, $limit);
|
||||||
|
$books = array();
|
||||||
|
foreach($parts as $p) {
|
||||||
|
$books = array_merge($books, $this->GetBooks($p));
|
||||||
|
}
|
||||||
|
return $books;
|
||||||
|
}
|
||||||
|
|
||||||
$bs = new BookSearch();
|
$bs = new BookSearch();
|
||||||
$bs->addQuery('code:('.implode(' OR ', $codes).')', null, false);
|
$bs->addQuery('code:('.implode(' OR ', $codes).')', null, false);
|
||||||
$results = $bs->getResults(0, count($codes));
|
$results = $bs->getResults(0, count($codes));
|
||||||
@@ -398,23 +411,7 @@ class NetBiblio extends WebService
|
|||||||
public function FindBooks($codes)
|
public function FindBooks($codes)
|
||||||
{
|
{
|
||||||
$this->CheckSession();
|
$this->CheckSession();
|
||||||
|
return $this->AddBookData($this->GetBooks(json_decode($codes)));
|
||||||
$codes = json_decode($codes);
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
if(count($codes) > $limit) {
|
|
||||||
$parts = array_chunk($codes, $limit);
|
|
||||||
$books = array();
|
|
||||||
foreach($parts as $p) {
|
|
||||||
$books = array_merge($books, $this->GetBooks($p));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$books = $this->GetBooks($codes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->AddBookData($books);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FindBook($code)
|
public function FindBook($code)
|
||||||
|
|||||||
Reference in New Issue
Block a user