From 32ad1d37ccf7cf10e17303128a29bee773689e4d Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 9 Apr 2014 11:56:24 -0400
Subject: [PATCH] Fixed bug: cannot retrieve all records from sharded results.

---
 .../VuFind/Search/Solr/MultiIndexListener.php | 20 +++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/module/VuFind/src/VuFind/Search/Solr/MultiIndexListener.php b/module/VuFind/src/VuFind/Search/Solr/MultiIndexListener.php
index 45595a416fe..36502f9cf85 100644
--- a/module/VuFind/src/VuFind/Search/Solr/MultiIndexListener.php
+++ b/module/VuFind/src/VuFind/Search/Solr/MultiIndexListener.php
@@ -117,12 +117,20 @@ class MultiIndexListener
         $backend = $event->getTarget();
         if ($backend === $this->backend) {
             $params = $event->getParam('params');
-            $shards = explode(',', implode(',', $params->get('shards')));
-            $fields = $this->getFields($shards);
-            $specs  = $this->getSearchSpecs($fields);
-            $backend->getQueryBuilder()->setSpecs($specs);
-            $facets = $params->get('facet.field') ?: array();
-            $params->set('facet.field', array_diff($facets, $fields));
+            if ($event->getParam('context') == 'retrieve') {
+                // If we're retrieving a record, we should pull all shards to be
+                // sure we find it.
+                $params->set('shards', implode(',', $this->shards));
+            } else {
+                // In any other context, we should make sure our field values are
+                // all legal.
+                $shards = explode(',', implode(',', $params->get('shards')));
+                $fields = $this->getFields($shards);
+                $specs  = $this->getSearchSpecs($fields);
+                $backend->getQueryBuilder()->setSpecs($specs);
+                $facets = $params->get('facet.field') ?: array();
+                $params->set('facet.field', array_diff($facets, $fields));
+            }
         }
         return $event;
     }
-- 
GitLab