Compare commits

...

10 Commits

Author SHA1 Message Date
Guillermo Pages
3c896ec409 fix: not returning all the results 2025-02-20 17:05:36 +01:00
Guillermo Pages
7e8302c830 unknwon: some code laying around 2024-12-11 00:54:08 +01:00
Guillermo Pages
898ac33376 fix: d strlen(): Passing null to parameter #1 () of type string is deprecated 2024-12-11 00:53:11 +01:00
Guillermo Pages
4671e4845a fix: using whole codes instead of parts results in lag 2022-07-01 14:31:24 +02:00
Guillermo Pages
17fe057765 fix: returning a list of only count limit when codes count > limit 2022-07-01 09:26:11 +02:00
Guillermo Pages
bf49549002 fix: set back to original with isset test 2021-09-01 10:00:48 +02:00
Guillermo Pages
2999de9cbd fix: set back to original with isset test 2021-09-01 10:00:40 +02:00
Guillermo Pages
62ac0b2512 fix: no results returned 2021-09-01 09:53:28 +02:00
Guillermo Pages
88d8ceed0b fix: Undefined array key 'id' 2021-09-01 09:49:27 +02:00
Guillermo Pages
36b243e0d4 feat: allow retrieving the query object 2021-09-01 09:39:50 +02:00

View File

@@ -83,7 +83,7 @@ class BookSearch
if($queryField == 'mediaType' and $queryText=='noCDS'){
$queryText='-mediaType:CDS';
} else if (strlen($queryField) > 0) {
} else if (isset($queryField) && strlen($queryField) > 0) {
$queryText = sprintf('%s:"%s"', $queryField, $queryText);
}
@@ -104,6 +104,10 @@ class BookSearch
$this->filterQueryParts[] = sprintf('%s:[%s TO %s]', $field, $min, $max);
}
public function getQuery() {
return $this->query;
}
public function addSortField($field, $order = \SolrQuery::ORDER_DESC)
{
$this->query->addSortField($field, $order);
@@ -175,6 +179,7 @@ class BookSearch
$books = array();
if(isset($results['response']['docs']) && is_array($results['response']['docs'])) {
foreach($results['response']['docs'] as $r) {
if (!isset($r['id'])) continue;
$books[$r['id']] = $r;
}
}
@@ -280,24 +285,35 @@ class BookSearch
* @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) {
// if we use array_merge here the numerical keys (book code) will be lost
$books += self::getBooks($p, $field);
$bs = self::getLastInstance();
$books = [];
foreach (array_chunk($codes, $limit) as $chunk) {
// Reset query state for this chunk
$bs->clearQueryParts();
$bs->addOrQuery($chunk, $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;
}
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->addOrQuery($codes, $field);
$results = $bs->getResults(0, $count);
$results = $bs->getResults(0, count($codes));
return $results['books'];
}