/** * Get the processed search results. * * @return \VuFind\Search\SolrCollection\Results */ public function getResults() { if (null === $this->results) { $driver = $this->getRecordDriver(); $request = $this->getRequest()->getQuery()->toArray() + $this->getRequest()->getPost()->toArray(); $rManager = $this->recommendManager; $cb = function ($runner, $params, $searchId) use($driver, $rManager) { $params->initFromRecordDriver($driver); $listener = new RecommendListener($rManager, $searchId); $listener->setConfig($params->getOptions()->getRecommendationSettings()); $listener->attach($runner->getEventManager()->getSharedManager()); }; $this->results = $this->runner->run($request, 'SolrCollection', $cb); } return $this->results; }
/** * 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) { // See if we can determine the label for the current search type; first // check for an override in the GET parameters, then look at the incoming // params object.... $typeLabel = $request->get('typeLabel'); $type = $request->get('type'); if (empty($typeLabel) && !empty($type)) { $typeLabel = $params->getOptions()->getLabelForBasicHandler($type); } // Extract a search query: $lookfor = $request->get($this->requestParam); if (empty($lookfor) && is_object($params)) { $lookfor = $params->getQuery()->getAllTerms(); } // Set up the callback to initialize the parameters: $limit = $this->limit; $callback = function ($runner, $params) use($lookfor, $limit, $typeLabel) { $params->setLimit($limit); $params->setBasicSearch($lookfor, $params->getOptions()->getHandlerForLabel($typeLabel)); }; // Perform the search: $this->results = $this->runner->run([], $this->getSearchClassId(), $callback); }
/** * Try a search and return results if found * * @param \VuFind\Search\SearchRunner $runner Search runner * @param array $params Search params * * @return bool|array Results object if records found, otherwise false */ protected function trySearch(\VuFind\Search\SearchRunner $runner, $params) { $mapFunc = function ($val) { return addcslashes($val, '"'); }; $query = ['join' => 'AND']; $i = 0; foreach ($params as $key => $param) { $query["type{$i}"][] = $key; $query["bool{$i}"] = ['AND']; if (is_array($param)) { $imploded = implode('" OR "', array_map($mapFunc, $param)); $query["lookfor{$i}"][] = "\"{$imploded}\""; } else { if (strstr($param, ' ')) { $param = "({$param})"; } $query["lookfor{$i}"][] = addcslashes($param, '"'); } ++$i; } $results = $runner->run($query); if ($results->getResultTotal() > 0) { return $results; } return false; }