示例#1
0
 /**
  * Create the Summon connector.
  * Detects clients relevant for target switching by IP and hostname
  *
  * @return Connector
  */
 protected function createConnector()
 {
     // Load credentials:
     $id = isset($this->config->Summon->apiId) ? $this->config->Summon->apiId : null;
     $key = isset($this->config->Summon->apiKey) ? $this->config->Summon->apiKey : null;
     $overrideCredentials = $this->getOverrideApiCredentialsFromProxy();
     if ($overrideCredentials !== false) {
         if (isset($overrideCredentials['apiId']) && !empty($overrideCredentials['apiId'])) {
             $id = $overrideCredentials['apiId'];
         }
         if (isset($overrideCredentials['apiKey']) && !empty($overrideCredentials['apiKey'])) {
             $key = $overrideCredentials['apiKey'];
         }
     }
     /** @var HttpClient $client */
     $client = $this->serviceLocator->get('VuFind\\Http')->createClient();
     $timeout = isset($this->summonConfig->General->timeout) ? $this->summonConfig->General->timeout : 30;
     $client->setOptions(array('timeout' => $timeout));
     $connector = new Connector($id, $key, array(), $client);
     $connector->setLogger($this->logger);
     return $connector;
 }
示例#2
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)
 {
     // Load 50 records at a time; this is the limit for Summon.
     $pageSize = 50;
     // Retrieve records a page at a time:
     $results = false;
     while (count($ids) > 0) {
         $currentPage = array_splice($ids, 0, $pageSize, []);
         $query = new SummonQuery(null, ['idsToFetch' => $currentPage, 'pageNumber' => 1, 'pageSize' => $pageSize]);
         $next = $this->createRecordCollection($this->connector->query($query));
         if (!$results) {
             $results = $next;
         } else {
             foreach ($next->getRecords() as $record) {
                 $results->add($record);
             }
         }
     }
     $this->injectSourceIdentifier($results);
     return $results;
 }
 /**
  * Create the Summon connector.
  *
  * @return Connector
  */
 protected function createConnector()
 {
     // Load credentials:
     $id = isset($this->config->Summon->apiId) ? $this->config->Summon->apiId : null;
     $key = isset($this->config->Summon->apiKey) ? $this->config->Summon->apiKey : null;
     // Build HTTP client:
     $client = $this->serviceLocator->get('VuFind\\Http')->createClient();
     $timeout = isset($this->summonConfig->General->timeout) ? $this->summonConfig->General->timeout : 30;
     $client->setOptions(['timeout' => $timeout]);
     $options = ['authedUser' => $this->isAuthed()];
     $connector = new Connector($id, $key, $options, $client);
     $connector->setLogger($this->logger);
     return $connector;
 }
示例#4
0
 /**
  * @return void
  */
 public function testDataAmountMoreThanZero()
 {
     $result = $this->connector->query(new Query('a'));
     $this->assertTrue(count($result['documents']) > 0, "More than zero documents found.");
 }
示例#5
0
 /**
  * Perform normalization and analysis of Summon return value.
  *
  * @param array $input The raw response from Summon
  *
  * @throws \SerialsSolutions_Summon_Exception
  * @return array       The processed response from Summon
  */
 protected function process($input)
 {
     $result = parent::process($input);
     // Process highlighting/snippets:
     foreach ($result['documents'] as $i => $current) {
         // Remove snippets if not desired:
         if (!$this->snippets) {
             unset($result['documents'][$i]['Snippet']);
         }
     }
     return $result;
 }