/** * Does not actually modify the result set, but tracks the search keywords. * * (non-PHPdoc) * @see Tx_Solr_ResultSetModifier::modifyResultSet() */ public function modifyResultSet(Tx_Solr_PiResults_ResultsCommand $resultCommand, array $resultSet) { $this->configuration = $resultCommand->getParentPlugin()->getConfiguration(); $keywords = $resultCommand->getParentPlugin()->getSearch()->getQuery()->getKeywordsCleaned(); 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 query and returns the modified query as result * * @param Tx_Solr_PiResults_ResultsCommand $resultCommand The search result command * @param array $resultDocument Result document * @return array The document with fields as array */ public function modifyResultDocument($resultCommand, array $resultDocument) { $this->search = $resultCommand->getParentPlugin()->getSearch(); $configuration = Tx_Solr_Util::getSolrConfiguration(); // 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; }
/** * Modifies the given document and returns the modified document as result. * * @param Tx_Solr_PiResults_ResultsCommand $resultCommand The search result command * @param array $resultDocument Result document as array * @return array The document with fields as array */ public function modifyResultDocument($resultCommand, array $resultDocument) { $this->search = $resultCommand->getParentPlugin()->getSearch(); $configuration = Tx_Solr_Util::getSolrConfiguration(); $highlightedContent = $this->search->getHighlightedContent(); $highlightFields = \TYPO3\CMS\Core\Utility\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[] = tx_solr_Template::escapeMarkers($fragment); } $resultDocument[$highlightField] = implode(' ' . $configuration['search.']['results.']['resultsHighlighting.']['fragmentSeparator'] . ' ', $fragments); } } return $resultDocument; }
/** * 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 Tx_Solr_PiResults_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($resultCommand, array $resultDocument) { $searchWords = $resultCommand->getParentPlugin()->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; }