protected function getSortingLinks()
 {
     $sortHelper = GeneralUtility::makeInstance('Tx_Solr_Sorting', $this->configuration['search.']['sorting.']['options.']);
     $query = $this->search->getQuery();
     $queryLinkBuilder = GeneralUtility::makeInstance('Tx_Solr_Query_LinkBuilder', $query);
     $queryLinkBuilder->setLinkTargetPageId($this->parentPlugin->getLinkTargetPageId());
     $sortOptions = array();
     $urlParameters = GeneralUtility::_GP('tx_solr');
     $urlSortParameters = GeneralUtility::trimExplode(',', $urlParameters['sort']);
     $configuredSortOptions = $sortHelper->getSortOptions();
     foreach ($configuredSortOptions as $sortOptionName => $sortOption) {
         $sortDirection = $this->configuration['search.']['sorting.']['defaultOrder'];
         if (!empty($this->configuration['search.']['sorting.']['options.'][$sortOptionName . '.']['defaultOrder'])) {
             $sortDirection = $this->configuration['search.']['sorting.']['options.'][$sortOptionName . '.']['defaultOrder'];
         }
         $sortIndicator = $sortDirection;
         $currentSortOption = '';
         $currentSortDirection = '';
         foreach ($urlSortParameters as $urlSortParameter) {
             $explodedUrlSortParameter = explode(' ', $urlSortParameter);
             if ($explodedUrlSortParameter[0] == $sortOptionName) {
                 list($currentSortOption, $currentSortDirection) = $explodedUrlSortParameter;
                 break;
             }
         }
         // toggle sorting direction for the current sorting field
         if ($currentSortOption == $sortOptionName) {
             switch ($currentSortDirection) {
                 case 'asc':
                     $sortDirection = 'desc';
                     $sortIndicator = 'asc';
                     break;
                 case 'desc':
                     $sortDirection = 'asc';
                     $sortIndicator = 'desc';
                     break;
             }
         }
         if (!empty($this->configuration['search.']['sorting.']['options.'][$sortOptionName . '.']['fixedOrder'])) {
             $sortDirection = $this->configuration['search.']['sorting.']['options.'][$sortOptionName . '.']['fixedOrder'];
         }
         $sortParameter = $sortOptionName . ' ' . $sortDirection;
         $temp = array('link' => $queryLinkBuilder->getQueryLink($sortOption['label'], array('sort' => $sortParameter)), 'url' => $queryLinkBuilder->getQueryUrl(array('sort' => $sortParameter)), 'optionName' => $sortOptionName, 'field' => $sortOption['field'], 'label' => $sortOption['label'], 'is_current' => '0', 'direction' => $sortDirection, 'indicator' => $sortIndicator, 'current_direction' => ' ');
         // set sort indicator for the current sorting field
         if ($currentSortOption == $sortOptionName) {
             $temp['selected'] = 'selected="selected"';
             $temp['current'] = 'current';
             $temp['is_current'] = '1';
             $temp['current_direction'] = $sortIndicator;
         }
         // special case relevance: just reset the search to normal behavior
         if ($sortOptionName == 'relevance') {
             $temp['link'] = $queryLinkBuilder->getQueryLink($sortOption['label'], array('sort' => NULL));
             $temp['url'] = $queryLinkBuilder->getQueryUrl(array('sort' => NULL));
             unset($temp['direction'], $temp['indicator']);
         }
         $sortOptions[] = $temp;
     }
     return $sortOptions;
 }
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * Renders facets selected by the user.
  *
  * @return string rendered selected facets subpart
  */
 protected function renderUsedFacets()
 {
     $template = clone $this->parentPlugin->getTemplate();
     $template->workOnSubpart('used_facets');
     $query = $this->search->getQuery();
     $queryLinkBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_Query_LinkBuilder', $this->search->getQuery());
     /* @var $queryLinkBuilder Tx_Solr_Query_LinkBuilder */
     $queryLinkBuilder->setLinkTargetPageId($this->parentPlugin->getLinkTargetPageId());
     // URL parameters added to facet URLs may not need to be added to the facets reset URL
     if (!empty($this->configuration['search.']['faceting.']['facetLinkUrlParameters']) && isset($this->configuration['search.']['faceting.']['facetLinkUrlParameters.']['useForFacetResetLinkUrl']) && $this->configuration['search.']['faceting.']['facetLinkUrlParameters.']['useForFacetResetLinkUrl'] === '0') {
         $addedUrlParameters = \TYPO3\CMS\Core\Utility\GeneralUtility::explodeUrl2Array($this->configuration['search.']['faceting.']['facetLinkUrlParameters']);
         $addedUrlParameterKeys = array_keys($addedUrlParameters);
         foreach ($addedUrlParameterKeys as $addedUrlParameterKey) {
             if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($addedUrlParameterKey, 'tx_solr')) {
                 $addedUrlParameterKey = substr($addedUrlParameterKey, 8, -1);
                 $queryLinkBuilder->addUnwantedUrlParameter($addedUrlParameterKey);
             }
         }
     }
     $resultParameters = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('tx_solr');
     $filterParameters = array();
     if (isset($resultParameters['filter'])) {
         $filterParameters = (array) array_map('urldecode', $resultParameters['filter']);
     }
     $facetsInUse = array();
     foreach ($filterParameters as $filter) {
         // only split by the first ":" to allow the use of colons in the filter value
         list($filterName, $filterValue) = explode(':', $filter, 2);
         $facetConfiguration = $this->configuration['search.']['faceting.']['facets.'][$filterName . '.'];
         // don't render facets that should not be included in used facets
         if (isset($facetConfiguration['includeInUsedFacets']) && $facetConfiguration['includeInUsedFacets'] == '0') {
             continue;
         }
         $usedFacetRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_Facet_UsedFacetRenderer', $filterName, $filterValue, $filter, $this->parentPlugin->getTemplate(), $query);
         $usedFacetRenderer->setLinkTargetPageId($this->parentPlugin->getLinkTargetPageId());
         $facetToRemove = $usedFacetRenderer->render();
         $facetsInUse[] = $facetToRemove;
     }
     $template->addLoop('facets_in_use', 'remove_facet', $facetsInUse);
     $template->addVariable('remove_all_facets', array('url' => $queryLinkBuilder->getQueryUrl(array('filter' => array())), 'text' => '###LLL:faceting_removeAllFilters###'));
     $content = '';
     if (count($facetsInUse)) {
         $content = $template->render();
     }
     return $content;
 }
 /**
  * Builds the properties for the frequent search term markers.
  *
  * @param array $frequentSearchTerms Frequent search terms as array with terms as keys and hits as the value
  * @return array An array with content for the frequent terms markers
  */
 protected function getSearchTermMarkerProperties(array $frequentSearchTerms)
 {
     $frequentSearches = array();
     $minimumSize = $this->configuration['search.']['frequentSearches.']['minSize'];
     $maximumSize = $this->configuration['search.']['frequentSearches.']['maxSize'];
     if (count($frequentSearchTerms)) {
         $maximumHits = max(array_values($frequentSearchTerms));
         $minimumHits = min(array_values($frequentSearchTerms));
         $spread = $maximumHits - $minimumHits;
         $step = $spread == 0 ? 1 : ($maximumSize - $minimumSize) / $spread;
         foreach ($frequentSearchTerms as $term => $hits) {
             $size = round($minimumSize + ($hits - $minimumHits) * $step);
             $frequentSearches[] = array('term' => Tx_Solr_Template::escapeMarkers($term), 'hits' => $hits, 'style' => 'font-size: ' . $size . 'px', 'class' => 'tx-solr-frequent-term-' . $size, 'parameters' => '&q=' . html_entity_decode($term, ENT_NOQUOTES, 'UTF-8'), 'pid' => $this->parentPlugin->getLinkTargetPageId());
         }
     }
     return $frequentSearches;
 }
Beispiel #5
0
 /**
  * Prepares the content for the last search markers
  *
  * @return	array	An array with content for the last search markers
  */
 protected function getLastSearches()
 {
     $lastSearchesKeywords = array();
     switch ($this->configuration['search.']['lastSearches.']['mode']) {
         case 'user':
             $lastSearchesKeywords = $this->getLastSearchesFromSession();
             break;
         case 'global':
             $lastSearchesKeywords = $this->getLastSearchesFromDatabase($this->configuration['search.']['lastSearches.']['limit']);
             break;
     }
     // fill array for output
     $i = 0;
     $lastSearches = array();
     foreach ($lastSearchesKeywords as $keywords) {
         if (++$i > $this->configuration['search.']['lastSearches.']['limit']) {
             break;
         }
         $keywords = stripslashes($keywords);
         $lastSearches[] = array('q' => Tx_Solr_Template::escapeMarkers($keywords), 'parameters' => '&q=' . html_entity_decode($keywords, ENT_NOQUOTES, 'UTF-8'), 'pid' => $this->parentPlugin->getLinkTargetPageId());
     }
     return $lastSearches;
 }