예제 #1
0
 /**
  * Given an array of IDs and a record source, load a batch of records for
  * that source.
  *
  * @param array  $ids    Record IDs
  * @param string $source Record source
  *
  * @throws \Exception
  * @return array
  */
 public function loadBatchForSource($ids, $source = DEFAULT_SEARCH_BACKEND)
 {
     $cachedRecords = [];
     if (null !== $this->recordCache && $this->recordCache->isPrimary($source)) {
         // Try to load records from cache if source is cachable
         $cachedRecords = $this->recordCache->lookupBatch($ids, $source);
         // Check which records could not be loaded from the record cache
         foreach ($cachedRecords as $cachedRecord) {
             $key = array_search($cachedRecord->getUniqueId(), $ids);
             if ($key !== false) {
                 unset($ids[$key]);
             }
         }
     }
     // Try to load the uncached records from the original $source
     $genuineRecords = [];
     if (!empty($ids)) {
         $genuineRecords = $this->searchService->retrieveBatch($source, $ids)->getRecords();
         foreach ($genuineRecords as $genuineRecord) {
             $key = array_search($genuineRecord->getUniqueId(), $ids);
             if ($key !== false) {
                 unset($ids[$key]);
             }
         }
     }
     if (!empty($ids) && null !== $this->recordCache && $this->recordCache->isFallback($source)) {
         // Try to load missing records from cache if source is cachable
         $cachedRecords = $this->recordCache->lookupBatch($ids, $source);
     }
     // Merge records found in cache and records loaded from original $source
     $retVal = $genuineRecords;
     foreach ($cachedRecords as $cachedRecord) {
         $retVal[] = $cachedRecord;
     }
     return $retVal;
 }
예제 #2
0
파일: Loader.php 프로젝트: tillk/vufind
 /**
  * Given an array of IDs and a record source, load a batch of records for
  * that source.
  *
  * @param array  $ids    Record IDs
  * @param string $source Record source
  *
  * @throws \Exception
  * @return array
  */
 public function loadBatchForSource($ids, $source = 'VuFind')
 {
     return $this->searchService->retrieveBatch($source, $ids)->getRecords();
 }