예제 #1
0
 /**
  * Get a random ID from the Solr index.
  *
  * @return string
  */
 protected function getRandomBibId()
 {
     $source = $this->getRecordSource();
     $query = isset($this->config['Records']['query']) ? $this->config['Records']['query'] : '*:*';
     $result = $this->searchService->random($source, new Query($query), 1);
     if (count($result) === 0) {
         throw new \Exception('Problem retrieving random record from $source.');
     }
     return current($result->getRecords())->getUniqueId();
 }
예제 #2
0
 /**
  * Called at the end of the Search Params objects' initFromRequest() method.
  * This method is responsible for setting search parameters needed by the
  * recommendation module and for reading any existing search parameters that may
  * be needed.
  *
  * @param \VuFind\Search\Base\Params $params  Search parameter object
  * @param \Zend\StdLib\Parameters    $request Parameter object representing user
  * request.
  *
  * @return void
  */
 public function init($params, $request)
 {
     if ("retain" !== $this->mode) {
         $randomParams = $this->paramManager->get($params->getSearchClassId());
     } else {
         $randomParams = clone $params;
     }
     foreach ($this->filters as $filter) {
         $randomParams->addFilter($filter);
     }
     $query = $randomParams->getQuery();
     $paramBag = $randomParams->getBackendParameters();
     $this->results = $this->searchService->random($this->backend, $query, $this->limit, $paramBag)->getRecords();
 }