Esempio n. 1
0
 /**
  * Perform a search and return record collection.
  *
  * @param AbstractQuery $query  Search query
  * @param integer       $offset Search offset
  * @param integer       $limit  Search limit
  * @param ParamBag      $params Search backend parameters
  *
  * @return RecordCollectionInterface
  */
 public function search(AbstractQuery $query, $offset, $limit, ParamBag $params = null)
 {
     $baseParams = $this->getQueryBuilder()->build($query);
     if (null !== $params) {
         $baseParams->mergeWith($params);
     }
     $args = $this->paramBagToArray($baseParams);
     try {
         $response = $this->connector->query($args, $offset, $limit);
         // Apply default search if necessary:
         if ($response['recordCount'] < 1 && isset($this->defaultSearch)) {
             $args['search'] = $this->defaultSearch;
             $response = $this->connector->query($args, $offset, $limit);
         }
     } catch (\Exception $e) {
         throw new BackendException($e->getMessage(), $e->getCode(), $e);
     }
     $collection = $this->createRecordCollection($response);
     $this->injectSourceIdentifier($collection);
     return $collection;
 }
Esempio n. 2
0
 /**
  * Create the LibGuides connector.
  *
  * @return Connector
  */
 protected function createConnector()
 {
     // Load credentials:
     $iid = isset($this->libGuidesConfig->General->iid) ? $this->libGuidesConfig->General->iid : null;
     // Pick version:
     $ver = isset($this->libGuidesConfig->General->version) ? $this->libGuidesConfig->General->version : 1;
     // Build HTTP client:
     $client = $this->serviceLocator->get('VuFind\\Http')->createClient();
     $timeout = isset($this->libGuidesConfig->General->timeout) ? $this->libGuidesConfig->General->timeout : 30;
     $client->setOptions(['timeout' => $timeout]);
     $connector = new Connector($iid, $client, $ver);
     $connector->setLogger($this->logger);
     return $connector;
 }