/** * constructor for class tx_solr_viewhelper_Relevance */ public function __construct(array $arguments = array()) { if (is_null($this->search)) { $this->search = t3lib_div::makeInstance('tx_solr_Search'); $this->maxScore = $this->search->getMaximumResultScore(); } }
/** * Resolves the current iteration index (relative) of a loop to the absolute * number counting from zero of the total number of results. * * @param array $arguments * @return string */ public function execute(array $arguments = array()) { $numberOfResults = $this->search->getNumberOfResults(); $currentIterationIndex = $arguments[0]; $resultsPerPage = $this->search->getResultsPerPage(); $currentPage = 0; $getParameters = t3lib_div::_GET('tx_solr'); if (isset($getParameters['page'])) { $currentPage = intval($getParameters['page']); } return $currentPage * $resultsPerPage + $currentIterationIndex; }
/** * Modifies the search form by providing an additional marker linking to a * new query with the suggestions provided by Solr as the search terms. * * @param array An array of existing form markers * @param tx_solr_Template An isntance of the tempalte engine * @return array Array with additional markers for suggestions */ public function modifyForm(array $markers, tx_solr_Template $template) { $spellCheckingEnabled = $this->configuration['search.']['spellchecking']; if ($spellCheckingEnabled && $this->search->hasSearched()) { $suggestions = $this->search->getSpellcheckingSuggestions(); if ($suggestions) { $query = clone $this->search->getQuery(); $query->setKeywords($suggestions['collation']); $markers['suggestion'] = tslib_cObj::noTrimWrap($query->getQueryLink($query->getKeywords()), $this->configuration['search.']['spellchecking.']['wrap']); } } return $markers; }
/** * Creates a link to a given page with a given link text with the current * tx_solr parameters appended to the URL * * @param array Array of arguments, [0] is the link text, [1] is the (optional) page Id to link to (otherwise TSFE->id), [2] are additional URL parameters, [3] use cache, defaults to FALSE * @return string complete anchor tag with URL and link text */ public function execute(array $arguments = array()) { $linkText = $arguments[0]; $pageId = $arguments[1] ? intval($arguments[1]) : $GLOBALS['TSFE']->id; $additionalParameters = $arguments[2] ? $arguments[2] : ''; $useCache = $arguments[3] ? TRUE : FALSE; $query = $this->search->getQuery(); $prefix = 'tx_solr'; $getParameters = t3lib_div::_GET($prefix); $piVars = is_array($getParameters) ? $getParameters : array(); $queryParameters = array_merge($piVars, array('q' => $query->getKeywords())); $queryParameters = $query->removeUnwantedUrlParameters($queryParameters); $linkConfiguration = array('useCacheHash' => $useCache, 'no_cache' => FALSE, 'parameter' => $pageId, 'additionalParams' => t3lib_div::implodeArrayForUrl('', array($prefix => $queryParameters), '', TRUE) . $additionalParameters); return $this->contentObject->typoLink($linkText, $linkConfiguration); }
protected function renderUsedFacets() { $template = clone $this->parentPlugin->getTemplate(); $template->workOnSubpart('used_facets'); $query = $this->search->getQuery(); $query->setLinkTargetPageId($this->parentPlugin->getLinkTargetPageId()); $resultParameters = t3lib_div::_GET('tx_solr'); $filterParameters = array(); if (isset($resultParameters['filter'])) { $filterParameters = (array) array_map('urldecode', $resultParameters['filter']); } $facetsInUse = array(); foreach ($filterParameters as $filter) { list($filterName, $filterValue) = explode(':', $filter); $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 = t3lib_div::makeInstance('tx_solr_facet_UsedFacetRenderer', $filterName, $filterValue, $filter, $facetConfiguration, $this->parentPlugin->getTemplate(), $query); $facetToRemove = $usedFacetRenderer->render(); $facetsInUse[] = $facetToRemove; } $template->addLoop('facets_in_use', 'remove_facet', $facetsInUse); $template->addVariable('remove_all_facets', array('url' => $query->getQueryUrl(array('filter' => array())), 'text' => '###LLL:faceting_removeAllFilters###')); $content = ''; if (count($facetsInUse)) { $content = $template->render(); } return $content; }
protected function getSortingLinks() { $configuredSortingFields = $this->configuration['search.']['sorting.']['fields.']; $query = $this->search->getQuery(); $query->setLinkTargetPageId($this->parentPlugin->getLinkTargetPageId()); $sortingFields = array(); $urlParameters = t3lib_div::_GP('tx_solr'); $urlSortingParameter = $urlParameters['sort']; list($currentSortByField, $currentSortDirection) = explode(' ', $urlSortingParameter); foreach ($configuredSortingFields as $fieldName => $enabled) { if (substr($fieldName, -1) != '.' && $enabled) { $sortDirection = $this->configuration['search.']['sorting.']['defaultOrder']; $sortIndicator = $sortDirection; $sortParameter = $fieldName . ' ' . $sortDirection; // toggle sorting direction for the current sorting field if ($currentSortByField == $fieldName) { switch ($currentSortDirection) { case 'asc': $sortDirection = 'desc'; $sortIndicator = 'asc'; break; case 'desc': $sortDirection = 'asc'; $sortIndicator = 'desc'; break; } $sortParameter = $fieldName . ' ' . $sortDirection; } $temp = array('link' => $query->getQueryLink('###LLL:' . $configuredSortingFields[$fieldName . '.']['label'] . '###', array('sort' => $sortParameter)), 'url' => $query->getQueryUrl(array('sort' => $sortParameter)), 'field' => $fieldName, 'label' => '###LLL:' . $configuredSortingFields[$fieldName . '.']['label'] . '###', 'is_current' => $currentSortByField == $fieldName ? '1' : '0', 'direction' => $sortDirection, 'indicator' => $sortIndicator, 'current_direction' => ' '); // set sort indicator for the current sorting field if ($currentSortByField == $fieldName) { $temp['selected'] = 'selected="selected"'; $temp['current'] = 'current'; $temp['current_direction'] = $sortIndicator; } // special case relevancy: just reset the search to normal behavior if ($fieldName == 'relevancy') { $temp['link'] = $query->getQueryLink('###LLL:' . $configuredSortingFields[$fieldName . '.']['label'] . '###', array('sort' => NULL)); unset($temp['direction'], $temp['indicator']); } $sortingFields[] = $temp; } } return $sortingFields; }
/** * Determines if a facet has any options. * * @return boolean TRUE if no facet options are given, FALSE if facet options are given */ protected function isEmpty() { $isEmpty = FALSE; $facetCounts = $this->search->getFacetCounts(); $facetField = $this->facetConfiguration['field']; $facetOptions = (array) $facetCounts->facet_fields->{$facetField}; $facetOptionsCount = count($facetOptions); // facet options include '_empty_', if no options are given if ($facetOptionsCount == 1 && array_key_exists('_empty_', $facetOptions)) { $isEmpty = TRUE; } return $isEmpty; }
/** * constructor for class tx_solr_viewhelper_SortUrl */ public function __construct(array $arguments = array()) { $this->search = t3lib_div::makeInstance('tx_solr_Search'); $this->configuration = tx_solr_Util::getSolrConfiguration(); $this->query = $this->search->getQuery(); }
/** * Determines whether filters have been applied to the query or not. * * @return string 1 if filters are applied, 0 if not (for use in templates) */ protected function isFiltered() { $filters = $this->search->getQuery()->getFilters(); $filtered = !empty($filters); return $filtered ? '1' : '0'; }
/** * Initializes the Solr connection and tests the connection through a ping. * */ protected function initializeSearch() { $solrConnection = t3lib_div::makeInstance('tx_solr_ConnectionManager')->getConnectionByPageId($GLOBALS['TSFE']->id, $GLOBALS['TSFE']->sys_language_uid, $GLOBALS['TSFE']->MP); $this->search = t3lib_div::makeInstance('tx_solr_Search', $solrConnection); $this->solrAvailable = $this->search->ping(); }
/** * * */ public function getResultDocuments() { $this->executeQuery(); return $this->search->getResultDocuments(); }