/** * This method returns an array of strings matching the user's query for * display in the autocomplete box. * * @param string $query The user query * * @return array The suggestions for the provided query */ public function getSuggestions($query) { if (!is_object($this->searchObject)) { throw new \Exception('Please set configuration first.'); } try { $this->searchObject->getParams()->setBasicSearch($this->mungeQuery($query), $this->handler); $this->searchObject->getParams()->setSort($this->sortField); foreach ($this->filters as $current) { $this->searchObject->getParams()->addFilter($current); } // Perform the search: $searchResults = $this->searchObject->getResults(); // Build the recommendation list -- first we'll try with exact matches; // if we don't get anything at all, we'll try again with a less strict // set of rules. $results = $this->getSuggestionsFromSearch($searchResults, $query, true); if (empty($results)) { $results = $this->getSuggestionsFromSearch($searchResults, $query, false); } } catch (\Exception $e) { // Ignore errors -- just return empty results if we must. } return isset($results) ? array_unique($results) : []; }
/** * Process the jumpto parameter -- either redirect to a specific record and * return view model, or ignore the parameter and return false. * * @param \VuFind\Search\Base\Results $results Search results object. * * @return mixed */ protected function processJumpTo($results) { // Missing/invalid parameter? Ignore it: $jumpto = $this->params()->fromQuery('jumpto'); if (empty($jumpto) || !is_numeric($jumpto)) { return false; } // Parameter out of range? Ignore it: $recordList = $results->getResults(); if (!isset($recordList[$jumpto - 1])) { return false; } // If we got this far, we have a valid parameter so we should redirect // and report success: $url = $recordList[$jumpto - 1]->getUrl(); return $url ? $this->redirect()->toUrl($url) : false; }
/** * Process the jumpto parameter -- either redirect to a specific record and * return view model, or ignore the parameter and return false. * * @param \VuFind\Search\Base\Results $results Search results object. * * @return bool|\Zend\View\Model\ViewModel */ protected function processJumpTo($results) { // Missing/invalid parameter? Ignore it: $jumpto = $this->params()->fromQuery('jumpto'); if (empty($jumpto) || !is_numeric($jumpto)) { return false; } // Parameter out of range? Ignore it: $recordList = $results->getResults(); if (!isset($recordList[$jumpto - 1])) { return false; } // If we got this far, we have a valid parameter so we should redirect // and report success: $details = $this->getRecordRouter()->getTabRouteDetails($recordList[$jumpto - 1]); return $this->redirect()->toRoute($details['route'], $details['params']); }
/** * Represent the current search results as a feed. * * @param \VuFind\Search\Base\Results $results Search results to convert to * feed * @param string $currentPath Base path to display in feed * (leave null to load dynamically using currentpath view helper) * * @return Feed */ public function __invoke($results, $currentPath = null) { $this->registerExtension(); // Determine base URL if not already provided: if (is_null($currentPath)) { $currentPath = $this->getView()->plugin('currentpath')->__invoke(); } $serverUrl = $this->getView()->plugin('serverurl'); $baseUrl = $serverUrl($currentPath); // Create the parent feed $feed = new Feed(); $feed->setTitle($this->translate('Results for') . ' ' . $results->getParams()->getDisplayQuery()); $feed->setLink($baseUrl . $results->getUrlQuery()->setViewParam(null, false)); $feed->setFeedLink($baseUrl . $results->getUrlQuery()->getParams(false), $results->getParams()->getView()); $feed->setDescription($this->translate('Showing') . ' ' . $results->getStartRecord() . '-' . $results->getEndRecord() . ' ' . $this->translate('of') . ' ' . $results->getResultTotal()); $params = $results->getParams(); // add atom links for easier paging $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage(1, false), 'first', $params->getView()); if ($params->getPage() > 1) { $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($params->getPage() - 1, false), 'previous', $params->getView()); } $lastPage = ceil($results->getResultTotal() / $params->getLimit()); if ($params->getPage() < $lastPage) { $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($params->getPage() + 1, false), 'next', $params->getView()); } $feed->addOpensearchLink($baseUrl . $results->getUrlQuery()->setPage($lastPage, false), 'last', $params->getView()); // add opensearch fields $feed->setOpensearchTotalResults($results->getResultTotal()); $feed->setOpensearchItemsPerPage($params->getLimit()); $feed->setOpensearchStartIndex($results->getStartRecord() - 1); $feed->setOpensearchSearchTerms($params->getQuery()->getString()); $records = $results->getResults(); foreach ($records as $current) { $this->addEntry($feed, $current); } return $feed; }
/** * Process the jumpto parameter -- either redirect to a specific record and * return view model, or ignore the parameter and return false. * * @param \VuFind\Search\Base\Results $results Search results object. * * @return bool|\Zend\View\Model\ViewModel */ protected function processJumpTo($results) { // Jump to only result, if configured $default = null; $config = $this->getServiceLocator()->get('VuFind\\Config')->get('config'); if (isset($config->Record->jump_to_single_search_result) && $config->Record->jump_to_single_search_result && $results->getResultTotal() == 1) { $default = 1; } // Missing/invalid parameter? Ignore it: $jumpto = $this->params()->fromQuery('jumpto', $default); if (empty($jumpto) || !is_numeric($jumpto)) { return false; } // Parameter out of range? Ignore it: $recordList = $results->getResults(); if (!isset($recordList[$jumpto - 1])) { return false; } // If we got this far, we have a valid parameter so we should redirect // and report success: $details = $this->getRecordRouter()->getTabRouteDetails($recordList[$jumpto - 1]); return $this->redirect()->toRoute($details['route'], $details['params']); }
/** * Represent the current search results as a feed. * * @param \VuFind\Search\Base\Results $results Search results to convert to * feed * @param string $currentPath Base path to display in feed * (leave null to load dynamically using currentpath view helper) * * @return Feed */ public function __invoke($results, $currentPath = null) { $this->registerExtension(); // Determine base URL if not already provided: if (is_null($currentPath)) { $currentPath = $this->getView()->plugin('currentpath')->__invoke(); } $serverUrl = $this->getView()->plugin('serverurl'); $baseUrl = $serverUrl($currentPath); // Create the parent feed $feed = new Feed(); $translator = $this->getTranslator(); $feed->setTitle($translator('Results for') . ' ' . $results->getParams()->getDisplayQuery()); $feed->setLink($baseUrl . $results->getUrlQuery()->setViewParam(null, false)); $feed->setFeedLink($baseUrl . $results->getUrlQuery()->getParams(false), $results->getParams()->getView()); $records = $results->getResults(); $feed->setDescription($translator('Displaying the top') . ' ' . count($records) . ' ' . $translator('search results of') . ' ' . $results->getResultTotal() . ' ' . $translator('found')); foreach ($records as $current) { $this->addEntry($feed, $current); } return $feed; }