Esempio n. 1
0
 /**
  * Retrieve a batch of documents.
  *
  * @param array    $ids    Array of document identifiers
  * @param ParamBag $params Search backend parameters
  *
  * @return RecordCollectionInterface
  */
 public function retrieveBatch($ids, ParamBag $params = null)
 {
     $onCampus = null !== $params ? $params->get('onCampus') : [false];
     $onCampus = $onCampus ? $onCampus[0] : false;
     // Load 100 records at a time; this is a good number to avoid memory
     // problems while still covering a lot of ground.
     $pageSize = 100;
     // Retrieve records a page at a time:
     $results = false;
     while (count($ids) > 0) {
         $currentPage = array_splice($ids, 0, $pageSize, []);
         try {
             $response = $this->connector->getRecords($currentPage, $this->connector->getInstitutionCode(), $onCampus);
         } catch (\Exception $e) {
             throw new BackendException($e->getMessage(), $e->getCode(), $e);
         }
         $next = $this->createRecordCollection($response);
         if (!$results) {
             $results = $next;
         } else {
             foreach ($next->getRecords() as $record) {
                 $results->add($record);
             }
         }
     }
     $this->injectSourceIdentifier($results);
     return $results;
 }
Esempio n. 2
0
 /**
  * Retrieve a single document.
  *
  * @param string   $id     Document identifier
  * @param ParamBag $params Search backend parameters
  *
  * @return RecordCollectionInterface
  */
 public function retrieve($id, ParamBag $params = null)
 {
     try {
         $response = $this->connector->getRecord($id, $this->connector->getInstitutionCode());
     } catch (\Exception $e) {
         throw new BackendException($e->getMessage(), $e->getCode(), $e);
     }
     $collection = $this->createRecordCollection($response);
     $this->injectSourceIdentifier($collection);
     return $collection;
 }