From 716d317424ed99f1fef36ab839c9256e8ae7f5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lahmann?= <lahmann@ub.uni-leipzig.de> Date: Thu, 29 Oct 2015 09:18:08 -0400 Subject: [PATCH] Fixes shard support for retrieveBatch - fixes bugs when retrieving multiple records (e.g. in Cart/Home) --- .../src/VuFind/Search/Solr/MultiIndexListener.php | 7 ++++--- .../src/VuFindSearch/Backend/Solr/Backend.php | 12 +++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/module/VuFind/src/VuFind/Search/Solr/MultiIndexListener.php b/module/VuFind/src/VuFind/Search/Solr/MultiIndexListener.php index 150b91a96b5..163af6f520b 100644 --- a/module/VuFind/src/VuFind/Search/Solr/MultiIndexListener.php +++ b/module/VuFind/src/VuFind/Search/Solr/MultiIndexListener.php @@ -116,9 +116,10 @@ class MultiIndexListener $backend = $event->getTarget(); if ($backend === $this->backend) { $params = $event->getParam('params'); - if ($event->getParam('context') == 'retrieve') { - // If we're retrieving a record, we should pull all shards to be - // sure we find it. + $allShardsContexts = ['retrieve', 'retrieveBatch']; + if (in_array($event->getParam('context'), $allShardsContexts)) { + // If we're retrieving by id(s), we should pull all shards to be + // sure we find the right record(s). $params->set('shards', implode(',', $this->shards)); } else { // In any other context, we should make sure our field values are diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Backend.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Backend.php index 33025bc09cc..555c0a4aa3e 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Backend.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Backend.php @@ -163,6 +163,8 @@ class Backend extends AbstractBackend */ public function retrieveBatch($ids, ParamBag $params = null) { + $params = $params ?: new ParamBag(); + // Load 100 records at a time; this is a good number to avoid memory // problems while still covering a lot of ground. $pageSize = 100; @@ -177,13 +179,9 @@ class Backend extends AbstractBackend while (count($ids) > 0) { $currentPage = array_splice($ids, 0, $pageSize, []); $currentPage = array_map($formatIds, $currentPage); - $params = new ParamBag( - [ - 'q' => 'id:(' . implode(' OR ', $currentPage) . ')', - 'start' => 0, - 'rows' => $pageSize - ] - ); + $params->set('q', 'id:(' . implode(' OR ', $currentPage) . ')'); + $params->set('start', 0); + $params->set('rows', $pageSize); $this->injectResponseWriter($params); $next = $this->createRecordCollection( $this->connector->search($params) -- GitLab