本文整理汇总了PHP中ArticleSearch::_getSparseArray方法的典型用法代码示例。如果您正苦于以下问题:PHP ArticleSearch::_getSparseArray方法的具体用法?PHP ArticleSearch::_getSparseArray怎么用?PHP ArticleSearch::_getSparseArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArticleSearch
的用法示例。
在下文中一共展示了ArticleSearch::_getSparseArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: count
/**
* Return an array of search results matching the supplied
* keyword IDs in decreasing order of match quality.
* Keywords are supplied in an array of the following format:
* $keywords[ARTICLE_SEARCH_AUTHOR] = array('John', 'Doe');
* $keywords[ARTICLE_SEARCH_...] = array(...);
* $keywords[null] = array('Matches', 'All', 'Fields');
* @param $journal object The journal to search
* @param $keywords array List of keywords
* @param $publishedFrom object Search-from date
* @param $publishedTo object Search-to date
* @param $rangeInfo Information on the range of results to return
*/
function &retrieveResults(&$journal, &$keywords, $publishedFrom = null, $publishedTo = null, $rangeInfo = null)
{
// Fetch all the results from all the keywords into one array
// (mergedResults), where mergedResults[article_id]
// = sum of all the occurences for all keywords associated with
// that article ID.
// resultCount contains the sum of result counts for all keywords.
$mergedResults =& ArticleSearch::_getMergedArray($journal, $keywords, $publishedFrom, $publishedTo, $resultCount);
// Convert mergedResults into an array (frequencyIndicator =>
// $articleId).
// The frequencyIndicator is a synthetically-generated number,
// where higher is better, indicating the quality of the match.
// It is generated here in such a manner that matches with
// identical frequency do not collide.
$results =& ArticleSearch::_getSparseArray($mergedResults, $resultCount);
$totalResults = count($results);
// Use only the results for the specified page, if specified.
if ($rangeInfo && $rangeInfo->isValid()) {
$results = array_slice($results, $rangeInfo->getCount() * ($rangeInfo->getPage() - 1), $rangeInfo->getCount());
$page = $rangeInfo->getPage();
$itemsPerPage = $rangeInfo->getCount();
} else {
$page = 1;
$itemsPerPage = max($totalResults, 1);
}
// Take the range of results and retrieve the Article, Journal,
// and associated objects.
$results =& ArticleSearch::formatResults($results);
// Return the appropriate iterator.
$returner =& new VirtualArrayIterator($results, $totalResults, $page, $itemsPerPage);
return $returner;
}
示例2: array
/**
* Return an array of search results matching the supplied
* keyword IDs in decreasing order of match quality.
* Keywords are supplied in an array of the following format:
* $keywords[ARTICLE_SEARCH_AUTHOR] = array('John', 'Doe');
* $keywords[ARTICLE_SEARCH_...] = array(...);
* $keywords[null] = array('Matches', 'All', 'Fields');
* @param $journal object The journal to search
* @param $keywords array List of keywords
* @param $error string a reference to a variable that will
* contain an error message if the search service produces
* an error.
* @param $publishedFrom object Search-from date
* @param $publishedTo object Search-to date
* @param $rangeInfo Information on the range of results to return
* @return VirtualArrayIterator An iterator with one entry per retrieved
* article containing the article, published article, issue, journal, etc.
*/
function &retrieveResults(&$journal, &$keywords, &$error, $publishedFrom = null, $publishedTo = null, $rangeInfo = null)
{
// Pagination
if ($rangeInfo && $rangeInfo->isValid()) {
$page = $rangeInfo->getPage();
$itemsPerPage = $rangeInfo->getCount();
} else {
$page = 1;
$itemsPerPage = ARTICLE_SEARCH_DEFAULT_RESULT_LIMIT;
}
// Check whether a search plug-in jumps in to provide ranked search results.
$totalResults = null;
$results =& HookRegistry::call('ArticleSearch::retrieveResults', array(&$journal, &$keywords, $publishedFrom, $publishedTo, $page, $itemsPerPage, &$totalResults, &$error));
// If no search plug-in is activated then fall back to the
// default database search implementation.
if ($results === false) {
// Parse the query.
foreach ($keywords as $searchType => $query) {
$keywords[$searchType] = ArticleSearch::_parseQuery($query);
}
// Fetch all the results from all the keywords into one array
// (mergedResults), where mergedResults[article_id]
// = sum of all the occurences for all keywords associated with
// that article ID.
$mergedResults =& ArticleSearch::_getMergedArray($journal, $keywords, $publishedFrom, $publishedTo);
// Convert mergedResults into an array (frequencyIndicator =>
// $articleId).
// The frequencyIndicator is a synthetically-generated number,
// where higher is better, indicating the quality of the match.
// It is generated here in such a manner that matches with
// identical frequency do not collide.
$results =& ArticleSearch::_getSparseArray($mergedResults);
$totalResults = count($results);
// Use only the results for the specified page.
$offset = $itemsPerPage * ($page - 1);
$length = max($totalResults - $offset, 0);
$length = min($itemsPerPage, $length);
if ($length == 0) {
$results = array();
} else {
$results = array_slice($results, $offset, $length);
}
}
// Take the range of results and retrieve the Article, Journal,
// and associated objects.
$results =& ArticleSearch::formatResults($results);
// Return the appropriate iterator.
import('lib.pkp.classes.core.VirtualArrayIterator');
$returner = new VirtualArrayIterator($results, $totalResults, $page, $itemsPerPage);
return $returner;
}