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'){ 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));
return $books; $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 = 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'];
} }