Example #1
0
 /**
  * Initializes the search component.
  *
  * Sets the debug query parameter
  *
  */
 public function initializeSearchComponent()
 {
     $solrConfiguration = Util::getSolrConfiguration();
     if ($solrConfiguration->getEnabledDebugMode()) {
         $this->query->setDebugMode();
     }
 }
Example #2
0
 /**
  * Constructor
  *
  * @param array $arguments
  */
 public function __construct(array $arguments = array())
 {
     $configuration = Util::getSolrConfiguration();
     if (!empty($configuration['viewhelpers.']['multivalue.']['glue'])) {
         $this->glue = $configuration['viewhelpers.']['multivalue.']['glue'];
     }
 }
 /**
  * @return TypoScriptConfiguration|array
  */
 protected function getConfiguration()
 {
     if ($this->configuration == null) {
         $this->configuration = Util::getSolrConfiguration();
     }
     return $this->configuration;
 }
 /**
  * @test
  */
 public function canGetVariants()
 {
     $this->indexPageIdsFromFixture('can_get_searchResultSet.xml', [1, 2, 3, 4, 5, 6, 7, 8]);
     sleep(1);
     $solrConnection = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\ConnectionManager')->getConnectionByPageId(1, 0, 0);
     $typoScriptConfiguration = Util::getSolrConfiguration();
     $typoScriptConfiguration->mergeSolrConfiguration(['search.' => ['variants' => 1, 'variants.' => ['variantField' => 'subTitle', 'expand' => 1, 'limit' => 11]]]);
     $this->assertTrue($typoScriptConfiguration->getSearchVariants(), 'Variants are not enabled');
     $this->assertEquals('subTitle', $typoScriptConfiguration->getSearchVariantsField());
     $this->assertEquals(11, $typoScriptConfiguration->getSearchVariantsLimit());
     $search = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Search', $solrConnection);
     /** @var $searchResultsSetService \ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService */
     $searchResultsSetService = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Domain\\Search\\ResultSet\\SearchResultSetService', $typoScriptConfiguration, $search);
     /** @var $searchRequest SearchRequest */
     $searchRequest = GeneralUtility::makeInstance(SearchRequest::class);
     $searchRequest->setRawQueryString('*');
     $searchResultSet = $searchResultsSetService->search($searchRequest);
     $searchResults = $searchResultSet->getSearchResults();
     $firstResult = $searchResults[0];
     // We assume that the first result has three variants.
     $this->assertSame(3, count($firstResult->getVariants()));
     // And every variant is indicated to be a variant.
     foreach ($firstResult->getVariants() as $variant) {
         $this->assertTrue($variant->getIsVariant(), 'Document should be a variant');
     }
 }
Example #5
0
 /**
  * Creates a link to a given page with a given link text
  *
  * @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, [4] additional A tag parameters
  * @return string complete anchor tag with URL and link text
  */
 public function execute(array $arguments = array())
 {
     $linkText = $arguments[0];
     $additionalParameters = $arguments[2] ? $arguments[2] : '';
     $useCache = $arguments[3] ? true : false;
     $ATagParams = $arguments[4] ? $arguments[4] : '';
     // by default or if no link target is set, link to the current page
     $linkTarget = $GLOBALS['TSFE']->id;
     // if the link target is a number, interpret it as a page ID
     $linkArgument = trim($arguments[1]);
     if (is_numeric($linkArgument)) {
         $linkTarget = intval($linkArgument);
     } elseif (!empty($linkArgument) && is_string($linkArgument)) {
         /** @var \ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration $configuration */
         $configuration = Util::getSolrConfiguration();
         if ($configuration->isValidPath($linkArgument)) {
             try {
                 $typoscript = $configuration->getObjectByPath($linkArgument);
                 $pathExploded = explode('.', $linkArgument);
                 $lastPathSegment = array_pop($pathExploded);
                 $linkTarget = intval($typoscript[$lastPathSegment]);
             } catch (\InvalidArgumentException $e) {
                 // ignore exceptions caused by markers, but accept the exception for wrong TS paths
                 if (substr($linkArgument, 0, 3) != '###') {
                     throw $e;
                 }
             }
         } elseif (GeneralUtility::isValidUrl($linkArgument) || GeneralUtility::isValidUrl(GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . '/' . $linkArgument)) {
             // $linkTarget is an URL
             $linkTarget = filter_var($linkArgument, FILTER_SANITIZE_URL);
         }
     }
     $linkConfiguration = array('useCacheHash' => $useCache, 'no_cache' => false, 'parameter' => $linkTarget, 'additionalParams' => $additionalParameters, 'ATagParams' => $ATagParams);
     return $this->contentObject->typoLink($linkText, $linkConfiguration);
 }
Example #6
0
 /**
  * Renders the block of used / applied facets.
  *
  * @return string Rendered HTML representing the used facet.
  */
 public function render()
 {
     $solrConfiguration = Util::getSolrConfiguration();
     $facetOption = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Facet\\FacetOption', $this->facetName, $this->filterValue);
     $facetLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Facet\\LinkBuilder', $this->query, $this->facetName, $facetOption);
     /* @var $facetLinkBuilder LinkBuilder */
     $facetLinkBuilder->setLinkTargetPageId($this->linkTargetPageId);
     if ($this->facetConfiguration['type'] == 'hierarchy') {
         // FIXME decouple this
         $filterEncoder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\FilterEncoder\\Hierarchy');
         $facet = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Facet\\Facet', $this->facetName);
         $facetRenderer = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Facet\\HierarchicalFacetRenderer', $facet);
         $facetText = $facetRenderer->getLastPathSegmentFromHierarchicalFacetOption($filterEncoder->decodeFilter($this->filterValue));
     } else {
         $facetText = $facetOption->render();
     }
     $facetText = $this->getModifiedFacetTextFromHook($facetText);
     $contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
     $facetConfiguration = $solrConfiguration->getSearchFacetingFacetByName($this->facetName);
     $facetLabel = $contentObject->stdWrap($facetConfiguration['label'], $facetConfiguration['label.']);
     $removeFacetText = strtr($solrConfiguration->getSearchFacetingRemoveFacetLinkText(), array('@facetValue' => $this->filterValue, '@facetName' => $this->facetName, '@facetLabel' => $facetLabel, '@facetText' => $facetText));
     $removeFacetLink = $facetLinkBuilder->getRemoveFacetOptionLink($removeFacetText);
     $removeFacetUrl = $facetLinkBuilder->getRemoveFacetOptionUrl();
     $facetToRemove = array('link' => $removeFacetLink, 'url' => $removeFacetUrl, 'text' => $removeFacetText, 'value' => $this->filterValue, 'facet_name' => $this->facetName);
     return $facetToRemove;
 }
Example #7
0
 /**
  * Resolves a TS path and returns its value
  *
  * @param string $path a TS path, separated with dots
  * @return string
  */
 protected function resolveTypoScriptPath($path, $arguments = null)
 {
     $value = '';
     $pathExploded = explode('.', trim($path));
     $lastPathSegment = array_pop($pathExploded);
     /** @var \ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration $configuration */
     $configuration = Util::getSolrConfiguration();
     $pathBranch = $configuration->getObjectByPath($path);
     // generate ts content
     $cObj = $this->getContentObject();
     if (!isset($pathBranch[$lastPathSegment . '.'])) {
         $value = htmlspecialchars($pathBranch[$lastPathSegment]);
     } else {
         if (count($arguments)) {
             $data = array('arguments' => $arguments);
             $numberOfArguments = count($arguments);
             for ($i = 0; $i < $numberOfArguments; $i++) {
                 $data['argument_' . $i] = $arguments[$i];
             }
             $cObj->start($data);
         }
         $value = $cObj->cObjGetSingle($pathBranch[$lastPathSegment], $pathBranch[$lastPathSegment . '.']);
     }
     return $value;
 }
Example #8
0
 /**
  * Returns an URL that switches the sorting indicator according to the
  * given sorting direction
  *
  * @param array $arguments Expects 'asc' or 'desc' as sorting direction in key 0
  * @return string
  * @throws \InvalidArgumentException when providing an invalid sorting direction
  */
 public function execute(array $arguments = array())
 {
     $content = '';
     $sortDirection = trim($arguments[0]);
     $configuration = Util::getSolrConfiguration();
     $contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
     $defaultImagePrefix = 'EXT:solr/Resources/Public/Images/Indicator';
     $sortViewHelperConfiguration = $configuration->getViewHelpersSortIndicatorConfiguration();
     switch ($sortDirection) {
         case 'asc':
             $imageConfiguration = $sortViewHelperConfiguration['up.'];
             if (!isset($imageConfiguration['file'])) {
                 $imageConfiguration['file'] = $defaultImagePrefix . 'Up.png';
             }
             $content = $contentObject->cObjGetSingle('IMAGE', $imageConfiguration);
             break;
         case 'desc':
             $imageConfiguration = $sortViewHelperConfiguration['down.'];
             if (!isset($imageConfiguration['file'])) {
                 $imageConfiguration['file'] = $defaultImagePrefix . 'Down.png';
             }
             $content = $contentObject->cObjGetSingle('IMAGE', $imageConfiguration);
             break;
         case '###SORT.CURRENT_DIRECTION###':
         case '':
             // ignore
             break;
         default:
             throw new \InvalidArgumentException('Invalid sorting direction "' . $arguments[0] . '", must be "asc" or "desc".', 1390868460);
     }
     return $content;
 }
 /**
  * Exclude some html parts by class inside content wrapped with TYPO3SEARCH_begin and TYPO3SEARCH_end
  * markers.
  *
  * @param string $indexableContent HTML markup
  * @return string HTML
  */
 public function excludeContentByClass($indexableContent)
 {
     if (empty(trim($indexableContent))) {
         return html_entity_decode($indexableContent);
     }
     $excludeClasses = $this->getConfiguration()->getIndexQueuePagesExcludeContentByClassArray();
     if (count($excludeClasses) === 0) {
         return html_entity_decode($indexableContent);
     }
     $isInContent = Util::containsOneOfTheStrings($indexableContent, $excludeClasses);
     if (!$isInContent) {
         return html_entity_decode($indexableContent);
     }
     $doc = new \DOMDocument('1.0', 'UTF-8');
     libxml_use_internal_errors(true);
     $doc->loadHTML('<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . $indexableContent);
     $xpath = new \DOMXPath($doc);
     foreach ($excludeClasses as $excludePart) {
         $elements = $xpath->query("//*[contains(@class,'" . $excludePart . "')]");
         if (count($elements) == 0) {
             continue;
         }
         foreach ($elements as $element) {
             $element->parentNode->removeChild($element);
         }
     }
     $html = $doc->saveHTML($doc->documentElement->parentNode);
     // remove XML-Preamble, newlines and doctype
     $html = preg_replace('/(<\\?xml[^>]+\\?>|\\r?\\n|<!DOCTYPE.+?>)/imS', '', $html);
     $html = str_replace(array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $html);
     return $html;
 }
Example #10
0
 /**
  * Constructor
  *
  * @param array $arguments
  */
 public function __construct(array $arguments = array())
 {
     if (is_null($this->dateFormat) || is_null($this->contentObject)) {
         $configuration = Util::getSolrConfiguration();
         $this->dateFormat = $configuration['general.']['dateFormat.'];
         $this->contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
     }
 }
Example #11
0
 /**
  * Constructor.
  *
  * @param string $facetName Facet Name
  * @param int|string $facetOptionValue Facet option value
  * @param int $facetOptionNumberOfResults number of results to be returned when applying this option's filter
  */
 public function __construct($facetName, $facetOptionValue, $facetOptionNumberOfResults = 0)
 {
     $this->facetName = $facetName;
     $this->value = $facetOptionValue;
     $this->numberOfResults = intval($facetOptionNumberOfResults);
     $solrConfiguration = Util::getSolrConfiguration();
     $this->facetConfiguration = $solrConfiguration->getSearchFacetingFacetByName($this->facetName);
 }
Example #12
0
 /**
  * Constructor
  *
  * @param SolrService $solrConnection The Solr connection to use for searching
  */
 public function __construct(SolrService $solrConnection = null)
 {
     $this->solr = $solrConnection;
     if (is_null($solrConnection)) {
         $this->solr = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\ConnectionManager')->getConnectionByPageId($GLOBALS['TSFE']->id, $GLOBALS['TSFE']->sys_language_uid);
     }
     $this->configuration = Util::getSolrConfiguration();
 }
 /**
  * Works through the indexing queue and indexes the queued items into Solr.
  *
  * @return boolean Returns TRUE on success, FALSE if no items were indexed or none were found.
  */
 public function execute()
 {
     $executionSucceeded = false;
     $this->configuration = Util::getSolrConfigurationFromPageId($this->site->getRootPageId());
     $this->indexItems();
     $executionSucceeded = true;
     return $executionSucceeded;
 }
Example #14
0
 /**
  * Constructor
  *
  * @param array $arguments
  */
 public function __construct(array $arguments = array())
 {
     if (is_null($this->dateFormat) || is_null($this->contentObject)) {
         $configuration = Util::getSolrConfiguration();
         $this->dateFormat = $configuration->getValueByPathOrDefaultValue('plugin.tx_solr.general.dateFormat.', array('date' => 'd.m.Y H:i'));
         $this->contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
     }
 }
 /**
  * Initializes the search component.
  *
  */
 public function initializeSearchComponent()
 {
     $solrConfiguration = Util::getSolrConfiguration();
     if (!empty($solrConfiguration['statistics'])) {
         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchQuery']['statistics'] = 'ApacheSolrForTypo3\\Solr\\Query\\Modifier\\Statistics';
         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['processSearchResponse']['statistics'] = 'ApacheSolrForTypo3\\Solr\\Response\\Processor\\StatisticsWriter';
     }
 }
Example #16
0
 /**
  * Constructor.
  *
  * @param string $facetName Facet Name
  * @param integer|string $facetOptionValue Facet option value
  * @param integer $facetOptionNumberOfResults number of results to be returned when applying this option's filter
  */
 public function __construct($facetName, $facetOptionValue, $facetOptionNumberOfResults = 0)
 {
     $this->facetName = $facetName;
     $this->value = $facetOptionValue;
     $this->numberOfResults = intval($facetOptionNumberOfResults);
     $solrConfiguration = Util::getSolrConfiguration();
     $this->facetConfiguration = $solrConfiguration['search.']['faceting.']['facets.'][$this->facetName . '.'];
 }
Example #17
0
 /**
  * Expects a timestamp and converts it to an ISO 8601 date as needed by Solr.
  *
  * Example date output format: 1995-12-31T23:59:59Z
  * The trailing "Z" designates UTC time and is mandatory
  *
  * @param array Array of values, an array because of multivalued fields
  * @return array Modified array of values
  */
 public function process(array $values)
 {
     $results = array();
     foreach ($values as $timestamp) {
         $results[] = Util::timestampToIso($timestamp);
     }
     return $results;
 }
Example #18
0
 /**
  * Works through the indexing queue and indexes the queued items into Solr.
  *
  * @return boolean Returns TRUE on success, FALSE if no items were indexed or none were found.
  */
 public function execute()
 {
     $executionSucceeded = FALSE;
     $this->configuration = Util::getSolrConfigurationFromPageId($this->site->getRootPageId());
     $this->indexItems();
     $this->cleanIndex();
     $executionSucceeded = TRUE;
     return $executionSucceeded;
 }
Example #19
0
 /**
  * @test
  */
 public function getSiteHashForDomain()
 {
     $oldKey = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
     $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'testKey';
     $hash1 = Util::getSiteHashForDomain('www.test.de');
     $hash2 = Util::getSiteHashForDomain('www.test.de');
     $this->assertEquals('b17ca8164881e80e96a96529c16b19cc405c9bd0', $hash1);
     $this->assertEquals('b17ca8164881e80e96a96529c16b19cc405c9bd0', $hash2);
     $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = $oldKey;
 }
Example #20
0
 /**
  * @param TypoScriptConfiguration $solrConfiguration
  */
 public function __construct($solrConfiguration = null)
 {
     if (!is_null($solrConfiguration)) {
         $this->configuration = $solrConfiguration;
     } else {
         $this->configuration = Util::getSolrConfiguration();
     }
     $this->allConfiguredFacets = $this->configuration->getSearchFacetingFacets();
     $this->facetRendererFactory = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Facet\\FacetRendererFactory', $this->allConfiguredFacets);
 }
Example #21
0
 /**
  * Parses the given date range from a GET parameter and returns a Solr
  * date range filter.
  *
  * @param string $rangeFilter The range filter query string from the query URL
  * @param array $configuration Facet configuration
  * @return string Lucene query language filter to be used for querying Solr
  */
 public function decodeFilter($dateRange, array $configuration = array())
 {
     list($dateRangeStart, $dateRangeEnd) = explode(self::DELIMITER, $dateRange);
     $dateRangeEnd .= '59';
     // adding 59 seconds
     // TODO for PHP 5.3 use date_parse_from_format() / date_create_from_format() / DateTime::createFromFormat()
     $dateRangeFilter = '[' . Util::timestampToIso(strtotime($dateRangeStart));
     $dateRangeFilter .= ' TO ';
     $dateRangeFilter .= Util::timestampToIso(strtotime($dateRangeEnd)) . ']';
     return $dateRangeFilter;
 }
Example #22
0
 public function setUp()
 {
     Util::initializeTsfe('1');
     $GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
     $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['targetPage'] = '0';
     $GLOBALS['TSFE']->tmpl->setup['config.']['tx_realurl_enable'] = '0';
     // setup up ts objects
     $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['detailPage'] = 5050;
     $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['renderObjects.'] = array('testContent' => 'TEXT', 'testContent.' => array('field' => 'argument_0'), 'testContent2' => 'TEXT', 'testContent2.' => array('field' => 'argument_1', 'stripHtml' => 1));
     $this->fixtures = array('argument content', '<span>argument content with html</span>', 'third argument content');
     $this->viewHelper = new Ts();
 }
Example #23
0
 /**
  * Constructor
  */
 public function __construct(array $arguments = array())
 {
     $configuration = 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'];
     }
     if (isset($configuration['viewHelpers.']['crop.']['cropFullWords'])) {
         $this->cropFullWords = (bool) $configuration['viewHelpers.']['crop.']['cropFullWords'];
     }
 }
Example #24
0
 /**
  * Modifies the given query and returns the modified query as result
  *
  * @param ResultsCommand $resultCommand The search result command
  * @param array $resultDocument Result document
  * @return array The document with fields as array
  */
 public function modifyResultDocument(ResultsCommand $resultCommand, array $resultDocument)
 {
     $this->search = $resultCommand->getParentPlugin()->getSearchResultSetService()->getSearch();
     // only check whether a BE user is logged in, don't need to check
     // for enabled score analysis as we wouldn't be here if it was disabled
     if ($GLOBALS['TSFE']->beUserLogin) {
         $configuration = Util::getSolrConfiguration();
         $queryFields = $configuration->getSearchQueryQueryFields();
         $debugData = $this->search->getDebugResponse()->explain->{$resultDocument['id']};
         $scoreCalculationService = GeneralUtility::makeInstance(ScoreCalculationService::class);
         $resultDocument['score_analysis'] = $scoreCalculationService->getRenderedScores($debugData, $queryFields);
     }
     return $resultDocument;
 }
 public function setUp()
 {
     Util::initializeTsfe('1');
     $GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
     $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['targetPage'] = '0';
     $GLOBALS['TSFE']->tmpl->setup['config.']['tx_realurl_enable'] = '0';
     $facetName = 'TestFacet';
     $facetOptions = array('testoption' => 1);
     $facetConfiguration = array('selectingSelectedFacetOptionRemovesFilter' => 0, 'renderingInstruction');
     $parentPlugin = GeneralUtility::makeInstance('Tx_Solr_PiResults_Results');
     $parentPlugin->cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
     $parentPlugin->main('', array());
     $query = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query', array('test'));
     $this->facetRenderer = GeneralUtility::makeInstance('Tx_Solr_Facet_SimpleFacetRenderer', $facetName, $facetOptions, $facetConfiguration, $parentPlugin->getTemplate(), $query);
     $this->facetRenderer->setLinkTargetPageId($parentPlugin->getLinkTargetPageId());
 }
 /**
  * Modifies the given document and returns the modified document as result.
  *
  * @param ResultsCommand $resultCommand The search result command
  * @param array $resultDocument Result document as array
  * @return array The document with fields as array
  */
 public function modifyResultDocument(ResultsCommand $resultCommand, array $resultDocument)
 {
     $this->search = $resultCommand->getParentPlugin()->getSearch();
     $configuration = Util::getSolrConfiguration();
     $highlightedContent = $this->search->getHighlightedContent();
     $highlightFields = GeneralUtility::trimExplode(',', $configuration['search.']['results.']['resultsHighlighting.']['highlightFields'], true);
     foreach ($highlightFields as $highlightField) {
         if (!empty($highlightedContent->{$resultDocument['id']}->{$highlightField}[0])) {
             $fragments = array();
             foreach ($highlightedContent->{$resultDocument['id']}->{$highlightField} as $fragment) {
                 $fragments[] = Template::escapeMarkers($fragment);
             }
             $resultDocument[$highlightField] = implode(' ' . $configuration['search.']['results.']['resultsHighlighting.']['fragmentSeparator'] . ' ', $fragments);
         }
     }
     return $resultDocument;
 }
Example #27
0
 /**
  * Loads the initially defined local lang file
  *
  * @return void
  */
 protected function loadLL()
 {
     $configuration = Util::getSolrConfiguration();
     $this->localLang[$this->languageFile] = $this->languageFactory->getParsedData($this->languageFile, $this->llKey, $GLOBALS['TSFE']->renderCharset, 3);
     $localLangConfiguration = $configuration->getLocalLangConfiguration();
     if (count($localLangConfiguration) == 0) {
         return;
     }
     // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
     foreach ($localLangConfiguration as $language => $overrideLabels) {
         $language = substr($language, 0, -1);
         if (is_array($overrideLabels)) {
             foreach ($overrideLabels as $labelKey => $overrideLabel) {
                 if (!is_array($overrideLabel)) {
                     $this->localLang[$this->languageFile][$language][$labelKey] = array(array('source' => $overrideLabel));
                 }
             }
         }
     }
 }
Example #28
0
 /**
  * SuggestQuery constructor.
  *
  * @param string $keywords
  * @param TypoScriptConfiguration $solrConfiguration
  */
 public function __construct($keywords, $solrConfiguration = null)
 {
     $keywords = (string) $keywords;
     if ($solrConfiguration == null) {
         $solrConfiguration = Util::getSolrConfiguration();
     }
     parent::__construct('', $solrConfiguration);
     $this->configuration = $solrConfiguration->getObjectByPathOrDefault('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('*:*');
 }
Example #29
0
    /**
     * Gets a Solr connection.
     *
     * Instead of generating a new connection with each call, connections are
     * kept and checked whether the requested connection already exists. If a
     * connection already exists, it's reused.
     *
     * @param string $host Solr host (optional)
     * @param integer $port Solr port (optional)
     * @param string $path Solr path (optional)
     * @param string $scheme Solr scheme, defaults to http, can be https (optional)
     * @return SolrService A solr connection.
     */
    public function getConnection($host = '', $port = 8080, $path = '/solr/', $scheme = 'http')
    {
        $connection = null;
        if (empty($host)) {
            GeneralUtility::devLog('ApacheSolrForTypo3\\Solr\\ConnectionManager::getConnection() called with empty
				host parameter. Using configuration from TSFE, might be
				inaccurate. Always provide a host or use the getConnectionBy*
				methods.', 'solr', 2);
            $configuration = Util::getSolrConfiguration();
            $solrConfiguration = $configuration['solr.'];
            $host = $solrConfiguration['host'];
            $port = $solrConfiguration['port'];
            $path = $solrConfiguration['path'];
            $scheme = $solrConfiguration['scheme'];
        }
        $connectionHash = md5($scheme . '://' . $host . $port . $path);
        if (!isset(self::$connections[$connectionHash])) {
            $connection = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\SolrService', $host, $port, $path, $scheme);
            self::$connections[$connectionHash] = $connection;
        }
        return self::$connections[$connectionHash];
    }
Example #30
0
 /**
  * Processes a query and its response after searching for that query.
  *
  * @param Query $query The query that has been searched for.
  * @param \Apache_Solr_Response $response The response for the last query.
  */
 public function processResponse(Query $query, \Apache_Solr_Response $response)
 {
     $urlParameters = GeneralUtility::_GP('tx_solr');
     $keywords = $query->getKeywords();
     $filters = isset($urlParameters['filter']) ? $urlParameters['filter'] : array();
     if (empty($keywords)) {
         // do not track empty queries
         return;
     }
     $keywords = $this->sanitizeString($keywords);
     $sorting = '';
     if (!empty($urlParameters['sort'])) {
         $sorting = $this->sanitizeString($urlParameters['sort']);
     }
     $configuration = 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' => is_object($response->spellcheck->suggestions) ? (int) get_object_vars($response->spellcheck->suggestions) : 0, '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(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $ipMaskLength), 'page' => (int) $urlParameters['page'], 'keywords' => $keywords, 'filters' => serialize($filters), 'sorting' => $sorting, 'parameters' => serialize($response->responseHeader->params));
     $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_solr_statistics', $insertFields);
 }