/**
  * Return the number of results for a Solr query respecting the allowed sites
  *
  * @return int
  */
 public function getNumberOfResults()
 {
     $solrConfiguration = Tx_Solr_Util::getSolrConfiguration();
     $allowedSites = Tx_Solr_Util::resolveSiteHashAllowedSites(GeneralUtility::_GP('id'), $solrConfiguration['search.']['query.']['allowedSites']);
     $q = GeneralUtility::_GP('q');
     /** @var \Tx_Solr_Query $query */
     $query = GeneralUtility::makeInstance('\\Tx_Solr_Query', $q);
     $query->setFieldList(array('title', 'url', 'teaser', 'score'));
     $query->setUserAccessGroups(explode(',', $GLOBALS['TSFE']->gr_list));
     $query->setSiteHashFilter($allowedSites);
     $this->searcher->getSearch()->search($query);
     $response = $this->searcher->getSearch()->getResponse();
     if (1 > $response->response->numFound) {
         $query->useRawQueryString(true);
         $response = $this->searcher->getSearch()->search($query);
     }
     return (int) $response->response->numFound;
 }
 /**
  * Generates the options for the results per page switch.
  *
  * @return array Array of results per page switch options.
  */
 public function getResultsPerPageOptions()
 {
     $resultsPerPageOptions = array();
     $resultsPerPageSwitchOptions = GeneralUtility::intExplode(',', $this->configuration['search.']['results.']['resultsPerPageSwitchOptions'], TRUE);
     $currentNumberOfResultsShown = $this->parentPlugin->getNumberOfResultsPerPage();
     $queryLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $this->parentPlugin->getSearch()->getQuery());
     $queryLinkBuilder->removeUnwantedUrlParameter('resultsPerPage');
     $queryLinkBuilder->setLinkTargetPageId($this->parentPlugin->getLinkTargetPageId());
     foreach ($resultsPerPageSwitchOptions as $option) {
         $selected = '';
         $selectedClass = '';
         if ($option == $currentNumberOfResultsShown) {
             $selected = ' selected="selected"';
             $selectedClass = ' class="currentNumberOfResults"';
         }
         $resultsPerPageOptions[] = array('value' => $option, 'selected' => $selected, 'selectedClass' => $selectedClass, 'url' => $queryLinkBuilder->getQueryUrl(array('resultsPerPage' => $option)));
     }
     return $resultsPerPageOptions;
 }
예제 #3
0
 /**
  * Gets the results for the suggested keywords.
  *
  * Conducts a new search using the suggested keywords and uses that search
  * to render the regular results command.
  *
  * @return string The rendered results command for the results of the suggested keywords.
  */
 protected function getSuggestionResults()
 {
     $spellChecker = GeneralUtility::makeInstance('Tx_Solr_SpellChecker');
     $suggestedKeywords = $spellChecker->getCollatedSuggestion();
     $suggestionResults = '';
     if (!empty($suggestedKeywords)) {
         $plugin = $this->parentPlugin;
         $search = $this->parentPlugin->getSearch();
         $query = clone $search->getQuery();
         $query->setKeywords($suggestedKeywords);
         $search->search($query);
         $resultsCommand = GeneralUtility::makeInstance('Tx_Solr_PiResults_ResultsCommand', $plugin);
         $commandVariables = $resultsCommand->execute();
         $suggestionResults = $plugin->renderCommand('results', $commandVariables);
     }
     return $suggestionResults;
 }