improve FindBooks for great number by operating in chunk
This commit is contained in:
@@ -78,7 +78,7 @@ class BookSearch
|
|||||||
|
|
||||||
$books = isset($results['response']['docs']) && $results['response']['docs'] ?
|
$books = isset($results['response']['docs']) && $results['response']['docs'] ?
|
||||||
array_map(function($o) { return (array) $o; }, $results['response']['docs']) :
|
array_map(function($o) { return (array) $o; }, $results['response']['docs']) :
|
||||||
false;
|
array();
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'count' => $results['response']['numFound'],
|
'count' => $results['response']['numFound'],
|
||||||
|
|||||||
@@ -212,16 +212,33 @@ class NetBiblio extends WebService
|
|||||||
$this->getUser()->deleteWish($bookNr);
|
$this->getUser()->deleteWish($bookNr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function GetBooks(array $codes) {
|
||||||
|
$bs = new BookSearch();
|
||||||
|
$bs->addQuery('code:('.implode(' OR ', $codes).')', null, false);
|
||||||
|
$results = $bs->getResults(0, count($codes));
|
||||||
|
return $results['books'];
|
||||||
|
}
|
||||||
|
|
||||||
public function FindBooks($codes)
|
public function FindBooks($codes)
|
||||||
{
|
{
|
||||||
$this->CheckSession();
|
$this->CheckSession();
|
||||||
|
|
||||||
$codes = json_decode($codes);
|
$codes = json_decode($codes);
|
||||||
$bs = new BookSearch();
|
|
||||||
$bs->addQuery('code:('.implode(' OR ', $codes).')', null, false);
|
|
||||||
$results = $bs->getResults(0, count($codes));
|
|
||||||
return $results['books'] ? $this->AddBookData($results['books']) : array();
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetFiles(array $ids)
|
private function GetFiles(array $ids)
|
||||||
@@ -367,11 +384,7 @@ class NetBiblio extends WebService
|
|||||||
public function FindBook($code)
|
public function FindBook($code)
|
||||||
{
|
{
|
||||||
$this->CheckSession();
|
$this->CheckSession();
|
||||||
|
return reset($this->AddBookData($this->GetBooks(array($code))));
|
||||||
$bs = new BookSearch();
|
|
||||||
$bs->addQuery($code, 'code');
|
|
||||||
$results = $bs->getResults(0, 1);
|
|
||||||
return $results['books'] ? reset($this->AddBookData($results['books'])) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetRandomBooks($number = 100, $seed = null) {
|
public function GetRandomBooks($number = 100, $seed = null) {
|
||||||
@@ -381,8 +394,7 @@ class NetBiblio extends WebService
|
|||||||
|
|
||||||
$bs = new BookSearch();
|
$bs = new BookSearch();
|
||||||
$bs->addSortField('random_'.$seed);
|
$bs->addSortField('random_'.$seed);
|
||||||
$results = $bs->getResults(0, $number);
|
return $this->AddBookData($bs->getResults(0, $number));
|
||||||
return $results['books'] ? $this->AddBookData($results['books']) : array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Search($query, $start, $limit)
|
public function Search($query, $start, $limit)
|
||||||
@@ -470,11 +482,7 @@ class NetBiblio extends WebService
|
|||||||
'facets' => $results['facets'],
|
'facets' => $results['facets'],
|
||||||
);
|
);
|
||||||
|
|
||||||
if($results['books']) {
|
return array_merge($data, $this->AddBookData($results['books']));
|
||||||
$data = array_merge($data, $this->AddBookData($results['books']));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ListOfReaders()
|
public function ListOfReaders()
|
||||||
|
|||||||
Reference in New Issue
Block a user