Load the keywords array from a given search filter.
public getKeywordsFromSearchFilters ( $searchFilters ) : array | ||
$searchFilters | array Search filters as returned from ArticleSearch::getSearchFilters() | |
Результат | array | Keyword array as required by SubmissionSearch::retrieveResults() |
/** * AJAX request for search query auto-completion. * @param $args array * @param $request Request * @return JSON string */ function queryAutocomplete($args, $request) { $this->validate(null, $request); // Check whether auto-suggest is enabled. $suggestionList = array(); $lucenePlugin = $this->_getLucenePlugin(); $enabled = (bool) $lucenePlugin->getSetting(0, 'autosuggest'); if ($enabled) { // Retrieve search criteria from the user input. $articleSearch = new ArticleSearch(); $searchFilters = $articleSearch->getSearchFilters($request); // Get the autosuggest input and remove it from // the filter array. $autosuggestField = $request->getUserVar('searchField'); $userInput = $searchFilters[$autosuggestField]; if (isset($searchFilters[$autosuggestField])) { unset($searchFilters[$autosuggestField]); } // Instantiate a search request. $searchRequest = new SolrSearchRequest(); $searchRequest->setJournal($searchFilters['searchJournal']); $searchRequest->setFromDate($searchFilters['fromDate']); $searchRequest->setToDate($searchFilters['toDate']); $keywords = $articleSearch->getKeywordsFromSearchFilters($searchFilters); $searchRequest->addQueryFromKeywords($keywords); // Get the web service. $solrWebService = $lucenePlugin->getSolrWebService(); /* @var $solrWebService SolrWebService */ $suggestions = $solrWebService->getAutosuggestions($searchRequest, $autosuggestField, $userInput, (int) $lucenePlugin->getSetting(0, 'autosuggestType')); // Prepare a suggestion list as understood by the // autocomplete JS handler. foreach ($suggestions as $suggestion) { $suggestionList[] = array('label' => $suggestion, 'value' => $suggestion); } } // Return the suggestions as JSON message. $json = new JSONMessage(true, $suggestionList); return $json->getString(); }
/** * Show the search form * @param $args array * @param $request PKPRequest */ function search($args, $request) { $this->validate(null, $request); // Get and transform active filters. $articleSearch = new ArticleSearch(); $searchFilters = $articleSearch->getSearchFilters($request); $keywords = $articleSearch->getKeywordsFromSearchFilters($searchFilters); // Get the range info. $rangeInfo = $this->getRangeInfo($request, 'search'); // Retrieve results. $error = ''; $results = $articleSearch->retrieveResults($request, $searchFilters['searchJournal'], $keywords, $error, $searchFilters['fromDate'], $searchFilters['toDate'], $rangeInfo); // Prepare and display the search template. $this->setupTemplate($request); $templateMgr = TemplateManager::getManager($request); $templateMgr->setCacheability(CACHEABILITY_NO_STORE); // Result set ordering options. $orderByOptions = $articleSearch->getResultSetOrderingOptions($request); $templateMgr->assign('searchResultOrderOptions', $orderByOptions); $orderDirOptions = $articleSearch->getResultSetOrderingDirectionOptions(); $templateMgr->assign('searchResultOrderDirOptions', $orderDirOptions); // Result set ordering selection. list($orderBy, $orderDir) = $articleSearch->getResultSetOrdering($request); $templateMgr->assign('orderBy', $orderBy); $templateMgr->assign('orderDir', $orderDir); // Similar documents. $templateMgr->assign('simDocsEnabled', true); // Result set display. $templateMgr->assign('jsLocaleKeys', array('search.noKeywordError')); $this->_assignSearchFilters($request, $templateMgr, $searchFilters); $templateMgr->assign('results', $results); $templateMgr->assign('error', $error); $templateMgr->display('search/search.tpl'); }
/** * Show the search form * @param $args array * @param $request PKPRequest */ function search($args, &$request) { $this->validate(); // Get and transform active filters. $searchFilters = ArticleSearch::getSearchFilters($request); $keywords = ArticleSearch::getKeywordsFromSearchFilters($searchFilters); // Get the range info. $rangeInfo = $this->getRangeInfo('search'); // Retrieve results. $error = ''; $results =& ArticleSearch::retrieveResults($searchFilters['searchJournal'], $keywords, $error, $searchFilters['fromDate'], $searchFilters['toDate'], $rangeInfo); // Prepare and display the search template. $this->setupTemplate($request); $templateMgr =& TemplateManager::getManager(); $templateMgr->setCacheability(CACHEABILITY_NO_STORE); $templateMgr->assign('jsLocaleKeys', array('search.noKeywordError')); $this->_assignSearchFilters($request, $templateMgr, $searchFilters); $templateMgr->assign_by_ref('results', $results); $templateMgr->assign('error', $error); $templateMgr->display('search/search.tpl'); }