/**
  * View the results of a search operation.
  * @param $args array
  * @param $request PKPRequest
  * @return string
  */
 function results($args, $request)
 {
     $templateMgr = TemplateManager::getManager($request);
     $press = $request->getPress();
     $this->setupTemplate($request);
     $query = $request->getUserVar('query');
     $templateMgr->assign('searchQuery', $query);
     // Fetch the monographs to display
     import('classes.search.MonographSearch');
     $monographSearch = new MonographSearch();
     $error = null;
     $resultsIterator = $monographSearch->retrieveResults($request, $press, array(null => $query), $error);
     $publishedMonographs = array();
     while ($result = $resultsIterator->next()) {
         $publishedMonograph = $result['publishedMonograph'];
         if ($publishedMonograph) {
             $publishedMonographs[$publishedMonograph->getId()] = $publishedMonograph;
         }
     }
     $templateMgr->assign('publishedMonographs', $publishedMonographs);
     // Display
     $templateMgr->display('catalog/results.tpl');
 }
 /**
  * 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[MONOGRAPH_SEARCH_AUTHOR] = array('John', 'Doe');
  * $keywords[MONOGRAPH_SEARCH_...] = array(...);
  * $keywords[null] = array('Matches', 'All', 'Fields');
  * @param $press object The press 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(&$press, &$keywords, $publishedFrom = null, $publishedTo = null, $rangeInfo = null)
 {
     // Fetch all the results from all the keywords into one array
     // (mergedResults), where mergedResults[monograph_id]
     // = sum of all the occurences for all keywords associated with
     // that monograph ID.
     // resultCount contains the sum of result counts for all keywords.
     $mergedResults =& MonographSearch::_getMergedArray($press, $keywords, $publishedFrom, $publishedTo, $resultCount);
     // Convert mergedResults into an array (frequencyIndicator =>
     // $monographId).
     // 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 =& MonographSearch::_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 Monograph, Press,
     // and associated objects.
     $results =& MonographSearch::formatResults($results);
     // Return the appropriate iterator.
     import('lib.pkp.classes.core.VirtualArrayIterator');
     $returner = new VirtualArrayIterator($results, $totalResults, $page, $itemsPerPage);
     return $returner;
 }