Compare commits
10 Commits
988e3bac90
...
3c896ec409
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c896ec409 | ||
|
|
7e8302c830 | ||
|
|
898ac33376 | ||
|
|
4671e4845a | ||
|
|
17fe057765 | ||
|
|
bf49549002 | ||
|
|
2999de9cbd | ||
|
|
62ac0b2512 | ||
|
|
88d8ceed0b | ||
|
|
36b243e0d4 |
@@ -83,7 +83,7 @@ class BookSearch
|
|||||||
|
|
||||||
if($queryField == 'mediaType' and $queryText=='noCDS'){
|
if($queryField == 'mediaType' and $queryText=='noCDS'){
|
||||||
$queryText='-mediaType:CDS';
|
$queryText='-mediaType:CDS';
|
||||||
} else if (strlen($queryField) > 0) {
|
} else if (isset($queryField) && strlen($queryField) > 0) {
|
||||||
$queryText = sprintf('%s:"%s"', $queryField, $queryText);
|
$queryText = sprintf('%s:"%s"', $queryField, $queryText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +104,10 @@ class BookSearch
|
|||||||
$this->filterQueryParts[] = sprintf('%s:[%s TO %s]', $field, $min, $max);
|
$this->filterQueryParts[] = sprintf('%s:[%s TO %s]', $field, $min, $max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getQuery() {
|
||||||
|
return $this->query;
|
||||||
|
}
|
||||||
|
|
||||||
public function addSortField($field, $order = \SolrQuery::ORDER_DESC)
|
public function addSortField($field, $order = \SolrQuery::ORDER_DESC)
|
||||||
{
|
{
|
||||||
$this->query->addSortField($field, $order);
|
$this->query->addSortField($field, $order);
|
||||||
@@ -175,6 +179,7 @@ class BookSearch
|
|||||||
$books = array();
|
$books = array();
|
||||||
if(isset($results['response']['docs']) && is_array($results['response']['docs'])) {
|
if(isset($results['response']['docs']) && is_array($results['response']['docs'])) {
|
||||||
foreach($results['response']['docs'] as $r) {
|
foreach($results['response']['docs'] as $r) {
|
||||||
|
if (!isset($r['id'])) continue;
|
||||||
$books[$r['id']] = $r;
|
$books[$r['id']] = $r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,24 +285,35 @@ 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();
|
||||||
if($count > $limit) {
|
$books = [];
|
||||||
$parts = array_chunk($codes, $limit);
|
foreach (array_chunk($codes, $limit) as $chunk) {
|
||||||
$books = array();
|
// Reset query state for this chunk
|
||||||
foreach($parts as $p) {
|
$bs->clearQueryParts();
|
||||||
// if we use array_merge here the numerical keys (book code) will be lost
|
$bs->addOrQuery($chunk, $field);
|
||||||
$books += self::getBooks($p, $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;
|
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
|
||||||
|
* check self::getBooks(array $codes, $field = 'code') for a chunked request
|
||||||
|
* in chunks if we are above the limit. 15 was found by testing and seems to be a sweet spot
|
||||||
|
*/
|
||||||
|
public static function getBooksFull(array $codes, $field = 'code') {
|
||||||
$bs = self::getLastInstance();
|
$bs = self::getLastInstance();
|
||||||
$bs->addOrQuery($codes, $field);
|
$bs->addOrQuery($codes, $field);
|
||||||
|
$results = $bs->getResults(0, count($codes));
|
||||||
$results = $bs->getResults(0, $count);
|
|
||||||
return $results['books'];
|
return $results['books'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user