Ejemplo n.º 1
0
 /**
  * Initializes the search component.
  *
  * Sets the debug query parameter
  *
  */
 public function initializeSearchComponent()
 {
     $solrConfiguration = Tx_Solr_Util::getSolrConfiguration();
     if ($solrConfiguration['enableDebugMode']) {
         $this->query->setDebugMode();
     }
 }
 /**
  * Initializes the search component.
  *
  *
  */
 public function initializeSearchComponent()
 {
     if ($this->searchConfiguration['results.']['showDocumentScoreAnalysis']) {
         $this->query->setDebugMode();
         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifyResultDocument']['scoreAnalysis'] = 'Tx_Solr_ResultDocumentModifier_ScoreAnalyzer';
         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchForm']['queryAnalysis'] = 'Tx_Solr_PiResults_QueryAnalyzerFormModifier';
     }
 }
 /**
  * Initializes the search component.
  *
  *
  */
 public function initializeSearchComponent()
 {
     if ($this->searchConfiguration['results.']['siteHighlighting']) {
         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifyResultDocument']['siteHighlighter'] = 'Tx_Solr_ResultDocumentModifier_SiteHighlighter';
     }
     if ($this->searchConfiguration['results.']['resultsHighlighting']) {
         $this->query->setHighlighting(TRUE, $this->searchConfiguration['results.']['resultsHighlighting.']['fragmentSize']);
         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifyResultDocument']['highlighting'] = 'Tx_Solr_PiResults_HighlightingResultDocumentModifier';
     }
 }
Ejemplo n.º 4
0
 /**
  * Initializes the search component.
  *
  * Sets the sorting query parameters
  *
  */
 public function initializeSearchComponent()
 {
     if (!empty($this->searchConfiguration['query.']['sortBy'])) {
         $this->query->addQueryParameter('sort', $this->searchConfiguration['query.']['sortBy']);
     }
     $solrGetParameters = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('tx_solr');
     if (!empty($this->searchConfiguration['sorting']) && !empty($solrGetParameters['sort']) && preg_match('/^([a-z0-9_]+ (asc|desc)[, ]*)*([a-z0-9_]+ (asc|desc))+$/i', $solrGetParameters['sort'])) {
         $sortHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_Sorting', $this->searchConfiguration['sorting.']['options.']);
         $sortField = $sortHelper->getSortFieldFromUrlParameter($solrGetParameters['sort']);
         $this->query->setSorting($sortField);
     }
 }
Ejemplo n.º 5
0
 /**
  * Modifies the given query and adds the parameters necessary for faceted
  * search.
  *
  * @param Tx_Solr_Query The query to modify
  * @return Tx_Solr_Query The modified query with faceting parameters
  */
 public function modifyQuery(Tx_Solr_Query $query)
 {
     $query->setFaceting();
     $this->buildFacetingParameters();
     $this->addFacetQueryFilters();
     foreach ($this->facetParameters as $facetParameter => $value) {
         $query->addQueryParameter($facetParameter, $value);
     }
     foreach ($this->facetFilters as $filter) {
         $query->addFilter($filter);
     }
     return $query;
 }
 /**
  * Processes a query and its response after searching for that query.
  *
  * @param	Tx_Solr_Query	The query that has been searched for.
  * @param	Apache_Solr_Response	The response for the last query.
  */
 public function processResponse(Tx_Solr_Query $query, Apache_Solr_Response $response)
 {
     $urlParameters = t3lib_div::_GP('tx_solr');
     $keywords = $query->getKeywords();
     $filters = isset($urlParameters['filter']) ? $urlParameters['filter'] : array();
     if (empty($keywords)) {
         // do not track empty queries
         return;
     }
     $keywords = t3lib_div::removeXSS($keywords);
     $keywords = htmlentities($keywords, ENT_QUOTES, $GLOBALS['TSFE']->metaCharset);
     $configuration = Tx_Solr_Util::getSolrConfiguration();
     if ($configuration['search.']['frequentSearches.']['useLowercaseKeywords']) {
         $keywords = strtolower($keywords);
     }
     $ipMaskLength = (int) $configuration['statistics.']['anonymizeIP'];
     $insertFields = array('pid' => $GLOBALS['TSFE']->id, 'root_pid' => $GLOBALS['TSFE']->tmpl->rootLine[0]['uid'], 'tstamp' => $GLOBALS['EXEC_TIME'], 'language' => $GLOBALS['TSFE']->sys_language_uid, 'num_found' => $response->response->numFound, 'suggestions_shown' => (int) get_object_vars($response->spellcheck->suggestions), 'time_total' => $response->debug->timing->time, 'time_preparation' => $response->debug->timing->prepare->time, 'time_processing' => $response->debug->timing->process->time, 'feuser_id' => (int) $GLOBALS['TSFE']->fe_user->user['uid'], 'cookie' => $GLOBALS['TSFE']->fe_user->id, 'ip' => $this->applyIpMask(t3lib_div::getIndpEnv('REMOTE_ADDR'), $ipMaskLength), 'page' => (int) $urlParameters['page'], 'keywords' => $keywords, 'filters' => serialize($filters), 'sorting' => $urlParameters['sort'] ? $urlParameters['sort'] : '', 'parameters' => serialize($response->responseHeader->params));
     $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_solr_statistics', $insertFields);
 }
Ejemplo n.º 7
0
 /**
  * Initializes the search component.
  *
  * Sets minimum match, boost function, and boost query.
  *
  */
 public function initializeSearchComponent()
 {
     if (!empty($this->searchConfiguration['query.']['minimumMatch'])) {
         $this->query->setMinimumMatch($this->searchConfiguration['query.']['minimumMatch']);
     }
     if (!empty($this->searchConfiguration['query.']['boostFunction'])) {
         $this->query->setBoostFunction($this->searchConfiguration['query.']['boostFunction']);
     }
     if (!empty($this->searchConfiguration['query.']['boostQuery'])) {
         $this->query->setBoostQuery($this->searchConfiguration['query.']['boostQuery']);
     }
     if (!empty($this->searchConfiguration['query.']['boostQuery.'])) {
         $boostQueries = array();
         $boostConfiguration = $this->searchConfiguration['query.']['boostQuery.'];
         foreach ($boostConfiguration as $query) {
             $boostQueries[] = $query;
         }
         $this->query->setBoostQuery($boostQueries);
     }
 }
Ejemplo n.º 8
0
 /**
  * Generates a html link - an anchor tag.
  *
  * TODO currently everything in $additionalQueryParameters is prefixed with tx_solr,
  * allow arbitrary parameters, too (either filter them out or introduce a new 4th parameter)
  *
  * @param string $linkText Link Text
  * @param array $additionalQueryParameters Additional query parameters
  * @param array $typolinkOptions Typolink Options
  * @return string A html link
  */
 public function getQueryLink($linkText, array $additionalQueryParameters = array(), array $typolinkOptions = array())
 {
     $queryParameters = array_merge($this->getPluginParameters(), $additionalQueryParameters);
     $queryParameters = $this->removeUnwantedUrlParameters($queryParameters);
     $queryGetParameter = '';
     $keywords = $this->query->getKeywords();
     if (!empty($keywords)) {
         $queryGetParameter = '&q=' . $keywords;
     }
     $linkConfiguration = array('useCacheHash' => FALSE, 'no_cache' => FALSE, 'parameter' => $this->linkTargetPageId, 'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', array($this->prefix => $queryParameters), '', TRUE) . $this->getUrlParameters() . $queryGetParameter);
     // merge linkConfiguration with typolinkOptions
     $linkConfiguration = array_merge($linkConfiguration, $typolinkOptions);
     return $this->contentObject->typoLink($linkText, $linkConfiguration);
 }
Ejemplo n.º 9
0
 /**
  * constructor for class Tx_Solr_SuggestQuery
  */
 public function __construct($keywords)
 {
     parent::__construct('');
     $this->configuration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['suggest.'];
     if (!empty($this->configuration['treatMultipleTermsAsSingleTerm'])) {
         $this->prefix = $this->escape($keywords);
     } else {
         $matches = array();
         preg_match('/^(:?(.* |))([^ ]+)$/', $keywords, $matches);
         $fullKeywords = trim($matches[2]);
         $partialKeyword = trim($matches[3]);
         $this->setKeywords($fullKeywords);
         $this->prefix = $this->escape($partialKeyword);
     }
     $this->setAlternativeQuery('*:*');
 }
Ejemplo n.º 10
0
 /**
  * Generates a URL.
  *
  * TODO currently everything in $additionalQueryParameters is prefixed with tx_solr,
  * allow arbitrary parameters, too (either filter them out or introduce a new 3rd parameter)
  *
  * @param array $additionalQueryParameters Additional query parameters
  * @param array $typolinkOptions Typolink Options
  * @return string A query URL
  */
 public function getQueryUrl(array $additionalQueryParameters = array(), array $typolinkOptions = array())
 {
     $queryParameters = array_merge($this->getPluginParameters(), $additionalQueryParameters);
     $queryParameters = $this->removeUnwantedUrlParameters($queryParameters);
     $queryKeywords = '';
     if ($this->query) {
         $queryKeywords = $this->query->getKeywords();
     }
     $queryGetParameter = '';
     if (!empty($queryKeywords)) {
         $queryGetParameter = '&q=' . $queryKeywords;
     }
     $linkConfiguration = array('useCacheHash' => FALSE, 'no_cache' => FALSE, 'parameter' => $this->linkTargetPageId, 'additionalParams' => $queryGetParameter . t3lib_div::implodeArrayForUrl('', array($this->prefix => $queryParameters), '', TRUE) . $this->getUrlParameters());
     // merge linkConfiguration with typolinkOptions
     $linkConfiguration = array_merge($linkConfiguration, $typolinkOptions);
     return htmlspecialchars($this->contentObject->typoLink_URL($linkConfiguration));
 }
Ejemplo n.º 11
0
 /**
  * Enables the query's debug mode to get more detailed information.
  *
  * @param	Tx_Solr_Query	The query to modify
  * @return	Tx_Solr_Query	The modified query with enabled debugging mode
  */
 public function modifyQuery(Tx_Solr_Query $query)
 {
     $query->setDebugMode(TRUE);
     return $query;
 }
Ejemplo n.º 12
0
 /**
  * @test
  * @depends settingGroupingTrueActivatesGrouping
  */
 public function settingGroupingFalseDeactivatesGrouping(Tx_Solr_Query $query)
 {
     $query->setGrouping(FALSE);
     $queryParameters = $query->getQueryParameters();
     foreach ($queryParameters as $queryParameter => $value) {
         $this->assertTrue(!t3lib_div::isFirstPartOfStr($queryParameter, 'group'), 'Query contains grouping parameter "' . $queryParameter . '"');
     }
 }
Ejemplo n.º 13
0
 /**
  * Enables the query's elevation mode.
  *
  * @param Tx_Solr_Query $query The query to modify
  * @return Tx_Solr_Query The modified query with enabled elevation mode
  */
 public function modifyQuery(Tx_Solr_Query $query)
 {
     $configuration = Tx_Solr_Util::getSolrConfiguration();
     $query->setQueryElevation($configuration['search.']['elevation'], $configuration['search.']['elevation.']['forceElevation'], $configuration['search.']['elevation.']['markElevatedResults']);
     return $query;
 }
Ejemplo n.º 14
0
 /**
  * constructor for class tx_solr_ExtractingQuery
  *
  * @param string $file Absolute path to the file to extract content and meta data from.
  */
 public function __construct($file)
 {
     parent::__construct('');
     $this->file = $file;
     $this->multiPartPostDataBoundary = '--' . md5(uniqid(time()));
 }
Ejemplo n.º 15
0
 /**
  * Initializes the search component.
  *
  *
  */
 public function initializeSearchComponent()
 {
     $allowedSites = Tx_Solr_Util::resolveSiteHashAllowedSites($GLOBALS['TSFE']->id, $this->searchConfiguration['query.']['allowedSites']);
     $this->query->setSiteHashFilter($allowedSites);
     $this->query->setUserAccessGroups(explode(',', $GLOBALS['TSFE']->gr_list));
 }
Ejemplo n.º 16
0
 /**
  * Gets the user's query term and cleans it so that it can be used in
  * templates f.e.
  *
  * @return string The cleaned user query.
  */
 public function getCleanUserQuery()
 {
     $userQuery = $this->getRawUserQuery();
     if (!is_null($userQuery)) {
         $userQuery = Tx_Solr_Query::cleanKeywords($userQuery);
     }
     // escape triple hashes as they are used in the template engine
     // TODO remove after switching to fluid templates
     $userQuery = Tx_Solr_Template::escapeMarkers($userQuery);
     return $userQuery;
 }
Ejemplo n.º 17
0
 /**
  * Initializes the search component.
  *
  *
  */
 public function initializeSearchComponent()
 {
     if ($this->searchConfiguration['spellchecking']) {
         $this->query->setSpellchecking();
     }
 }
Ejemplo n.º 18
0
 /**
  * Initializes additional filters configured through TypoScript and
  * Flexforms for use in regular queries and suggest queries.
  *
  * @param Tx_Solr_Query $query
  * @return void
  */
 protected function initializeAdditionalFilters(Tx_Solr_Query $query)
 {
     $additionalFilters = array();
     if (!empty($this->conf['search.']['query.']['filter.'])) {
         // special filter to limit search to specific page tree branches
         if (array_key_exists('__pageSections', $this->conf['search.']['query.']['filter.'])) {
             $query->setRootlineFilter($this->conf['search.']['query.']['filter.']['__pageSections']);
             unset($this->conf['search.']['query.']['filter.']['__pageSections']);
         }
         // all other regular filters
         foreach ($this->conf['search.']['query.']['filter.'] as $filterKey => $filter) {
             if (!is_array($this->conf['search.']['query.']['filter.'][$filterKey])) {
                 if (is_array($this->conf['search.']['query.']['filter.'][$filterKey . '.'])) {
                     $filter = $this->cObj->stdWrap($this->conf['search.']['query.']['filter.'][$filterKey], $this->conf['search.']['query.']['filter.'][$filterKey . '.']);
                 }
                 $additionalFilters[$filterKey] = $filter;
             }
         }
     }
     // flexform overwrites _all_ filters set through TypoScript
     $flexformFilters = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'filter', 'sQuery');
     if (!empty($flexformFilters)) {
         $additionalFilters = GeneralUtility::trimExplode('|', $flexformFilters);
     }
     $this->additionalFilters = $additionalFilters;
 }