public getSimilarityTerms ( $submissionId ) : null | array | ||
$submissionId | integer | |
return | null | array | An array of string keywords or null if some kind of error occurred. |
function getSimilarityTerms($submissionId)
{
// Check whether a search plugin provides terms for a similarity search.
$searchTerms = array();
$result = HookRegistry::call('ArticleSearch::getSimilarityTerms', array($submissionId, &$searchTerms));
// If no plugin implements the hook then use the subject keywords
// of the submission for a similarity search.
if ($result === false) {
// Retrieve the article.
$publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
/* @var $publishedArticleDao PublishedArticleDAO */
$article = $publishedArticleDao->getPublishedArticleByArticleId($submissionId);
if (is_a($article, 'PublishedArticle')) {
// Retrieve keywords (if any).
$searchTerms = $article->getLocalizedSubject();
// Tokenize keywords.
$searchTerms = trim(preg_replace('/\\s+/', ' ', strtr($searchTerms, ',;', ' ')));
if (!empty($searchTerms)) {
$searchTerms = explode(' ', $searchTerms);
}
}
}
return $searchTerms;
}
/** * @see templates/article/footer.tpl */ function callbackTemplateArticlePageFooter($hookName, $params) { $smarty =& $params[1]; $output =& $params[2]; // Identify similarity terms for the given article. $displayedArticle = $smarty->get_template_vars('article'); $articleId = $displayedArticle->getId(); import('classes.search.ArticleSearch'); $articleSearch = new ArticleSearch(); $searchTerms = $articleSearch->getSimilarityTerms($articleId); if (empty($searchTerms)) { return false; } // If we got similarity terms then execute a search with... // ... request, journal and error messages, ... $request = PKPApplication::getRequest(); $router = $request->getRouter(); $journal = $router->getContext($request); $error = null; // ... search keywords ... $query = implode(' ', $searchTerms); $keywords = array(null => $query); // ... and pagination. $rangeInfo = Handler::getRangeInfo($request, 'articlesBySimilarity'); $rangeInfo->setCount(RECOMMEND_BY_SIMILARITY_PLUGIN_COUNT); $results = $articleSearch->retrieveResults($request, $journal, $keywords, $error, null, null, $rangeInfo, array($articleId)); $smarty->assign('articlesBySimilarity', $results); $smarty->assign('articlesBySimilarityQuery', $query); $output .= $smarty->fetch($this->getTemplatePath() . 'articleFooter.tpl'); return false; }