/**
*/
function callbackRetrieveResults($hookName, $params)
{
assert($hookName == 'SubmissionSearch::retrieveResults');
// Unpack the parameters.
list($journal, $keywords, $fromDate, $toDate, $orderBy, $orderDir, $exclude, $page, $itemsPerPage) = $params;
$totalResults =& $params[9];
// need to use reference
$error =& $params[10];
// need to use reference
// Instantiate a search request.
$searchRequest = new SolrSearchRequest();
$searchRequest->setJournal($journal);
$searchRequest->setFromDate($fromDate);
$searchRequest->setToDate($toDate);
$searchRequest->setOrderBy($orderBy);
$searchRequest->setOrderDir($orderDir == 'asc' ? true : false);
$searchRequest->setPage($page);
$searchRequest->setItemsPerPage($itemsPerPage);
$searchRequest->addQueryFromKeywords($keywords);
$searchRequest->setExcludedIds($exclude);
// Configure alternative spelling suggestions.
$spellcheck = (bool) $this->getSetting(0, 'spellcheck');
$searchRequest->setSpellcheck($spellcheck);
// Configure highlighting.
$highlighting = (bool) $this->getSetting(0, 'highlighting');
$searchRequest->setHighlighting($highlighting);
// Configure faceting.
// 1) Faceting will be disabled for filtered search categories.
$activeFilters = array_keys($searchRequest->getQuery());
if (is_a($journal, 'Journal')) {
$activeFilters[] = 'journalTitle';
}
if (!empty($fromDate) || !empty($toDate)) {
$activeFilters[] = 'publicationDate';
}
// 2) Switch faceting on for enabled categories that have no
// active filters.
$facetCategories = array_values(array_diff($this->_getEnabledFacetCategories(), $activeFilters));
$searchRequest->setFacetCategories($facetCategories);
// Configure custom ranking.
$customRanking = (bool) $this->getSetting(0, 'customRanking');
if ($customRanking) {
$sectionDao = DAORegistry::getDAO('SectionDAO');
/* @var $sectionDao SectionDAO */
if (is_a($journal, 'Journal')) {
$sections = $sectionDao->getByJournalId($journal->getId());
} else {
$sections = $sectionDao->getAll();
}
while ($section = $sections->next()) {
/* @var $sections DAOResultFactory */
$section = $sections->next();
$sectionBoost = (double) $section->getData('rankingBoost');
if ($sectionBoost != 1.0) {
$searchRequest->addBoostFactor('section_id', $section->getId(), $sectionBoost);
}
}
unset($sections);
}
// Configure ranking-by-metric.
$rankingByMetric = (bool) $this->getSetting(0, 'rankingByMetric');
if ($rankingByMetric) {
// The 'usageMetricAll' field is an external file field containing
// multiplicative boost values calculated from usage metrics and
// normalized to values between 1.0 and 2.0.
$searchRequest->addBoostField('usageMetricAll');
}
// Call the solr web service.
$solrWebService =& $this->getSolrWebService();
$result = $solrWebService->retrieveResults($searchRequest, $totalResults);
if (is_null($result)) {
$error = $solrWebService->getServiceMessage();
$this->_informTechAdmin($error, $journal, true);
$error .= ' ' . __('plugins.generic.lucene.message.techAdminInformed');
return array();
} else {
// Store spelling suggestion, highlighting and faceting info
// internally. We cannot route these back through the request
// as the default search implementation does not support
// these features.
if ($spellcheck && isset($result['spellingSuggestion'])) {
$this->_spellingSuggestion = $result['spellingSuggestion'];
// Identify the field for which we got the suggestion.
foreach ($keywords as $bitmap => $searchPhrase) {
if (!empty($searchPhrase)) {
switch ($bitmap) {
case null:
$queryField = 'query';
break;
case SUBMISSION_SEARCH_INDEX_TERMS:
$queryField = 'indexTerms';
break;
default:
$articleSearch = new ArticleSearch();
$indexFieldMap = $articleSearch->getIndexFieldMap();
assert(isset($indexFieldMap[$bitmap]));
$queryField = $indexFieldMap[$bitmap];
}
}
}
$this->_spellingSuggestionField = $queryField;
}
if ($highlighting && isset($result['highlightedArticles'])) {
$this->_highlightedArticles = $result['highlightedArticles'];
}
if (!empty($facetCategories) && isset($result['facets'])) {
$this->_facets = $result['facets'];
}
// Return the scored results.
if (isset($result['scoredResults']) && !empty($result['scoredResults'])) {
return $result['scoredResults'];
} else {
return array();
}
}
}