Exemple #1
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) {
         $highScores = $this->analyzeScore($resultDocument);
         $resultDocument['score_analysis'] = $this->renderScoreAnalysis($highScores);
     }
     return $resultDocument;
 }
Exemple #2
0
 /**
  * Does not actually modify the result set, but tracks the search keywords.
  *
  * (non-PHPdoc)
  * @see ResultSetModifier::modifyResultSet()
  * @param \ApacheSolrForTypo3\Solr\Plugin\Results\ResultsCommand $resultCommand
  * @param array $resultSet
  * @return array
  */
 public function modifyResultSet(ResultsCommand $resultCommand, array $resultSet)
 {
     $keywords = $resultCommand->getParentPlugin()->getSearchResultSetService()->getSearch()->getQuery()->getKeywordsCleaned();
     $keywords = trim($keywords);
     if (empty($keywords)) {
         return $resultSet;
     }
     $configuration = $resultCommand->getParentPlugin()->getConfiguration();
     /** @var $lastSearchesService \ApacheSolrForTypo3\Solr\Domain\Search\LastSearches\LastSearchesService */
     $lastSearchesService = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Domain\\Search\\LastSearches\\LastSearchesService', $configuration, $GLOBALS['TSFE'], $GLOBALS['TYPO3_DB']);
     $lastSearchesService->addToLastSearches($keywords);
     return $resultSet;
 }
Exemple #3
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;
 }
 /**
  * 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()->getSearchResultSetService()->getSearch();
     $highlightedContent = $this->search->getHighlightedContent();
     foreach ($this->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(' ' . $this->fragmentSeparator . ' ', $fragments);
         }
     }
     return $resultDocument;
 }
 /**
  * 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;
 }
 /**
  * Does not actually modify the result set, but tracks the search keywords.
  *
  * (non-PHPdoc)
  * @see ResultSetModifier::modifyResultSet()
  * @param \ApacheSolrForTypo3\Solr\Plugin\Results\ResultsCommand $resultCommand
  * @param array $resultSet
  * @return array
  */
 public function modifyResultSet(ResultsCommand $resultCommand, array $resultSet)
 {
     $this->configuration = $resultCommand->getParentPlugin()->getConfiguration();
     $keywords = $resultCommand->getParentPlugin()->getSearch()->getQuery()->getKeywordsCleaned();
     $keywords = trim($keywords);
     if (empty($keywords)) {
         return $resultSet;
     }
     switch ($this->configuration['search.']['lastSearches.']['mode']) {
         case 'user':
             $this->storeKeywordsToSession($keywords);
             break;
         case 'global':
             $this->storeKeywordsToDatabase($keywords);
             break;
         default:
             throw new \UnexpectedValueException('Unknown mode for plugin.tx_solr.search.lastSearches.mode, valid modes are "user" or "global".', 1342456570);
     }
     return $resultSet;
 }
 /**
  * Modifies the given result document's url field by appending parameters
  * which will result in having the current search terms highlighted on the
  * target page.
  *
  * @param ResultsCommand $resultCommand The search result command
  * @param array $resultDocument The result document's fields as an array
  * @return array The document with fields as array
  */
 public function modifyResultDocument(ResultsCommand $resultCommand, array $resultDocument)
 {
     $searchWords = $resultCommand->getParentPlugin()->getSearchResultSetService()->getSearch()->getQuery()->getKeywordsCleaned();
     // remove quotes from phrase searches - they've been escaped by getCleanUserQuery()
     $searchWords = str_replace('"', '', $searchWords);
     $searchWords = GeneralUtility::trimExplode(' ', $searchWords, true);
     $url = $resultDocument['url'];
     $fragment = '';
     if (strpos($url, '#') !== false) {
         $explodedUrl = explode('#', $url);
         $fragment = $explodedUrl[1];
         $url = $explodedUrl[0];
     }
     $url .= strpos($url, '?') !== false ? '&' : '?';
     $url .= 'sword_list[]=' . array_shift($searchWords);
     foreach ($searchWords as $word) {
         $url .= '&sword_list[]=' . $word;
     }
     $url .= '&no_cache=1' . ($fragment ? '#' . $fragment : '');
     // eventually, replace the document's URL with the one that enables highlighting
     $resultDocument['url'] = $url;
     return $resultDocument;
 }