/**
  * Constructor for class tx_solr_facet_FacetRenderer
  *
  * @param	string	$facetName The name of the facet to render.
  * @param	tx_solr_Template	$template The template to use to render the facet.
  */
 public function __construct($facetName, tx_solr_Template $template)
 {
     $this->search = t3lib_div::makeInstance('tx_solr_Search');
     $this->facetName = $facetName;
     $this->template = $template;
     $this->solrConfiguration = tx_solr_Util::getSolrConfiguration();
     $this->facetConfiguration = $this->solrConfiguration['search.']['faceting.']['facets.'][$facetName . '.'];
     $this->linkTargetPageId = $GLOBALS['TSFE']->id;
 }
 /**
  * constructor for class tx_solr_viewhelper_Crop
  */
 public function __construct(array $arguments = array())
 {
     $configuration = tx_solr_Util::getSolrConfiguration();
     if (!empty($configuration['viewhelpers.']['crop.']['maxLength'])) {
         $this->maxLength = $configuration['viewhelpers.']['crop.']['maxLength'];
     }
     if (!empty($configuration['viewhelpers.']['crop.']['cropIndicator'])) {
         $this->cropIndicator = $configuration['viewhelpers.']['crop.']['cropIndicator'];
     }
 }
 /**
  * Renders the block of used / applied facets.
  *
  * @see tx_solr_FacetRenderer::render()
  * @return	string	Rendered HTML representing the used facet.
  */
 public function render()
 {
     $solrConfiguration = tx_solr_Util::getSolrConfiguration();
     $facetText = $this->renderOption($this->filterValue);
     $removeFacetText = strtr($solrConfiguration['search.']['faceting.']['removeFacetLinkText'], array('@facetValue' => $this->filterValue, '@facetName' => $this->facetName, '@facetText' => $facetText));
     $removeFacetLink = $this->buildRemoveFacetLink($removeFacetText, $this->filter);
     $removeFacetUrl = $this->buildRemoveFacetUrl($this->filter);
     $facetToRemove = array('link' => $removeFacetLink, 'url' => $removeFacetUrl, 'text' => $removeFacetText, 'name' => $this->filterValue);
     return $facetToRemove;
 }
 /**
  * constructor for class tx_solr_Query
  */
 public function __construct($keywords)
 {
     $this->solrConfiguration = tx_solr_Util::getSolrConfiguration();
     // TODO specify which fields to get exactly
     $this->returnFields = array('*', 'score');
     $this->setKeywords($keywords);
     $this->sorting = '';
     if (!empty($this->solrConfiguration['search.']['query.']['fields'])) {
         $this->setQueryFieldsFromString($this->solrConfiguration['search.']['query.']['fields']);
     }
     $this->linkTargetPageId = $this->solrConfiguration['search.']['targetPage'];
     if (empty($this->linkTargetPageId)) {
         $this->linkTargetPageId = $GLOBALS['TSFE']->id;
     }
     $this->id = ++self::$idCount;
 }
示例#5
0
#--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# TSFE initialization
tslib_eidtools::connectDB();
$pageId = filter_var(t3lib_div::_GET('id'), FILTER_SANITIZE_NUMBER_INT);
$languageId = filter_var(t3lib_div::_GET('L'), FILTER_VALIDATE_INT, array('options' => array('default' => 0, 'min_range' => 0)));
$TSFE = t3lib_div::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], $pageId, 0, TRUE);
$TSFE->initFEuser();
$TSFE->initUserGroups();
$TSFE->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
$TSFE->rootLine = $TSFE->sys_page->getRootLine($pageId, '');
$TSFE->initTemplate();
$TSFE->getConfigArray();
$TSFE->includeTCA();
$TSFE->sys_language_uid = $languageId;
$solrConfiguration = tx_solr_Util::getSolrConfiguration();
#--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
# Building Suggest Query
$suggestQuery = NULL;
$q = trim(t3lib_div::_GP('term'));
$suggestQuery = t3lib_div::makeInstance('tx_solr_SuggestQuery', $q);
$suggestQuery->setUserAccessGroups(explode(',', $TSFE->gr_list));
$suggestQuery->setSiteHash(tx_solr_Util::getSiteHash($pageId));
$language = 0;
if ($TSFE->sys_language_uid) {
    $language = $TSFE->sys_language_uid;
}
$suggestQuery->addFilter('language:' . $language);
$suggestQuery->setOmitHeader();
$additionalFilters = t3lib_div::_GET('filters');
if (!empty($additionalFilters)) {
 /**
  * Constructor for class tx_solr_pi_results_SpellcheckFormModifier
  *
  */
 public function __construct()
 {
     $this->search = t3lib_div::makeInstance('tx_solr_Search');
     $this->configuration = tx_solr_Util::getSolrConfiguration();
 }
 /**
  * Returns the number of results per Page.
  *
  * @return	int	number of results to show per page
  */
 public function getNumberOfResultsPerPage()
 {
     $configuration = tx_solr_Util::getSolrConfiguration();
     $resultsPerPageSwitchOptions = t3lib_div::intExplode(',', $configuration['search.']['results.']['resultsPerPageSwitchOptions']);
     $solrParameters = array();
     $solrPostParameters = t3lib_div::_POST('tx_solr');
     $solrGetParameters = t3lib_div::_GET('tx_solr');
     // check for GET parameters, POST takes precedence
     if (isset($solrGetParameters) && is_array($solrGetParameters)) {
         $solrParameters = $solrGetParameters;
     }
     if (isset($solrPostParameters) && is_array($solrPostParameters)) {
         $solrParameters = $solrPostParameters;
     }
     if (isset($solrParameters['resultsPerPage']) && in_array($solrParameters['resultsPerPage'], $resultsPerPageSwitchOptions)) {
         $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_solr_resultsPerPage', intval($solrParameters['resultsPerPage']));
         $this->resultsPerPageChanged = TRUE;
     }
     $defaultNumberOfResultsShown = $configuration['search.']['results.']['resultsPerPage'];
     $userSetNumberOfResultsShown = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_solr_resultsPerPage');
     $currentNumberOfResultsShown = $defaultNumberOfResultsShown;
     if (!is_null($userSetNumberOfResultsShown) && in_array($userSetNumberOfResultsShown, $resultsPerPageSwitchOptions)) {
         $currentNumberOfResultsShown = (int) $userSetNumberOfResultsShown;
     }
     if ($this->conf['search.']['allowEmptyQuery'] && empty($this->piVars['q'])) {
         // set number of rows to return to 0
         $currentNumberOfResultsShown = 0;
     }
     return $currentNumberOfResultsShown;
 }
 /**
  * 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();
 }
 /**
  * Retrieves the filter parmeters from the url and adds an additional facet
  * to create a link to add additional facets to a search result.
  *
  * @param	string	$facetToAdd Facet filter to add to the filter parameters
  * @return	array	An array of filter parameters
  */
 protected function addFacetAndEncodeFilterParameters($facetToAdd)
 {
     $solrConfiguration = tx_solr_Util::getSolrConfiguration();
     $resultParameters = t3lib_div::_GPmerged('tx_solr');
     $filterParameters = array();
     if (isset($resultParameters['filter']) && !$solrConfiguration['search.']['faceting.']['singleFacetMode']) {
         $filterParameters = array_map('urldecode', $resultParameters['filter']);
     }
     $filterParameters[] = $facetToAdd;
     $filterParameters = array_unique($filterParameters);
     $filterParameters = array_map('urlencode', $filterParameters);
     return $filterParameters;
 }
 protected function getResultsPerPageSwitch()
 {
     $template = clone $this->parentPlugin->getTemplate();
     $template->workOnSubpart('results_per_page_switch');
     $configuration = tx_solr_Util::getSolrConfiguration();
     $resultsPerPageSwitchOptions = t3lib_div::intExplode(',', $configuration['search.']['results.']['resultsPerPageSwitchOptions']);
     $currentNumberOfResultsShown = $this->parentPlugin->getNumberOfResultsPerPage();
     $selectOptions = array();
     foreach ($resultsPerPageSwitchOptions as $option) {
         $selected = '';
         $selectedClass = '';
         if ($option == $currentNumberOfResultsShown) {
             $selected = ' selected="selected"';
             $selectedClass = ' class="currentNumberOfResults"';
         }
         $selectOptions[] = array('value' => $option, 'selected' => $selected, 'selectedClass' => $selectedClass, 'url' => $this->parentPlugin->pi_linkTP_keepPIvars_url(array('resultsPerPage' => $option)));
     }
     $template->addLoop('options', 'option', $selectOptions);
     $form = array('action' => $this->parentPlugin->pi_linkTP_keepPIvars_url());
     $template->addVariable('form', $form);
     return $template->render();
 }
 /**
  * constructor for class tx_solr_query_modifier_Faceting
  */
 public function __construct()
 {
     $this->configuration = tx_solr_Util::getSolrConfiguration();
 }
示例#12
0
 /**
  *
  *
  */
 private function executeQuery()
 {
     $this->queryExecuted = true;
     $solrConnection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_solr_ConnectionManager')->getConnection();
     $search = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_solr_Search', $solrConnection);
     $query = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_solr_Query', $this->getKeywords());
     $solrConfiguration = \tx_solr_Util::getSolrConfiguration();
     $query->setFieldList($this->getFieldList());
     if ($this->hasSorting()) {
         $sortArray = $this->sorting;
         // Handle the case where the sorting array is like array('field', 'asc') instead of array('field' => 'asc')
         if (count($sortArray) == 2 && is_numeric(key($sortArray))) {
             $sortArray = array($sortArray[0] => $sortArray[1]);
         }
         $sorts = array();
         foreach ($sortArray as $field => $dir) {
             if ($dir != \tx_solr_Query::SORT_DESC && $dir != \tx_solr_Query::SORT_ASC) {
                 $dir = \tx_solr_Query::SORT_ASC;
                 // an implicit default
             }
             $sorts[] = "{$field} " . strtolower($dir);
         }
         $query->setSorting(implode(',', $sorts));
     }
     if ($this->boostQuery) {
         $query->setBoostQuery($this->boostQuery);
     }
     // Get default filters from the SOLR search configuration
     if (isset($solrConfiguration['search.']['query.']['filter.']) && is_array($solrConfiguration['search.']['query.']['filter.'])) {
         $defaultFilters = array();
         foreach ($solrConfiguration['search.']['query.']['filter.'] as $searchFilter) {
             $parts = explode(':', $searchFilter);
             $defaultFilters[$parts[0]] = $parts[1];
         }
         // Calling this will trigger any subclasses that may need to make modifications
         $this->setFilters($defaultFilters);
     }
     foreach ($this->filters as $filter) {
         $query->addFilter($filter);
     }
     $this->response = $search->search($query, $this->getQueryOffset(), $this->getQueryLimit());
     $this->body = json_decode($this->response->getRawResponse());
     $this->search = $search;
     $this->query = $query;
     $this->numFound = $this->body->response->numFound;
 }