Exemplo 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);
     }
     $this->connector->search($baseParams);
     /* Pazpar2 does not return all results immediately. Rather, we need to
      * occassionally check with the Pazpar2 server on the status of the
      * search.
      *
      * This loop will continue to wait until the configured level of
      * progress is reached or until the maximum query time has passed at
      * which time the existing results will be returned.
      */
     $queryStart = time();
     $progress = $this->getSearchProgress();
     while ($progress < $this->progressTarget && time() - $queryStart < $this->maxQueryTime) {
         sleep(1);
         $progress = $this->getSearchProgress();
     }
     $showParams = new ParamBag(['block' => 1, 'num' => $limit, 'start' => $offset]);
     $response = $this->connector->show($showParams);
     $hits = isset($response->hit) ? $response->hit : [];
     $collection = $this->createRecordCollection($hits, intval($response->merged), $offset);
     $this->injectSourceIdentifier($collection);
     return $collection;
 }