示例#1
0
 /**
  * Prepares the content for the last search markers
  *
  * @return	array	An array with content for the last search markers
  */
 protected function getLastSearches()
 {
     $lastSearchesKeywords = array();
     switch ($this->configuration['search.']['lastSearches.']['mode']) {
         case 'user':
             $lastSearchesKeywords = $this->getLastSearchesFromSession();
             break;
         case 'global':
             $lastSearchesKeywords = $this->getLastSearchesFromDatabase($this->configuration['search.']['lastSearches.']['limit']);
             break;
     }
     // fill array for output
     $i = 0;
     $lastSearches = array();
     foreach ($lastSearchesKeywords as $keywords) {
         if (++$i > $this->configuration['search.']['lastSearches.']['limit']) {
             break;
         }
         $keywords = stripslashes($keywords);
         $lastSearches[] = array('q' => Tx_Solr_Template::escapeMarkers($keywords), 'parameters' => '&q=' . html_entity_decode($keywords, ENT_NOQUOTES, 'UTF-8'), 'pid' => $this->parentPlugin->getLinkTargetPageId());
     }
     return $lastSearches;
 }
 /**
  * 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;
 }
示例#3
0
文件: Query.php 项目: sfsmfc/solr
 /**
  * Helper method to escape/encode keywords for use in HTML
  *
  * @param string $keywords Keywords to prepare for use in HTML
  * @return string Encoded keywords
  */
 public static function cleanKeywords($keywords)
 {
     $keywords = trim($keywords);
     $keywords = t3lib_div::removeXSS($keywords);
     $keywords = htmlentities($keywords, ENT_QUOTES, $GLOBALS['TSFE']->metaCharset);
     // escape triple hashes as they are used in the template engine
     // TODO remove after switching to fluid templates
     $keywords = Tx_Solr_Template::escapeMarkers($keywords);
     return $keywords;
 }
 /**
  * Builds the properties for the frequent search term markers.
  *
  * @param array $frequentSearchTerms Frequent search terms as array with terms as keys and hits as the value
  * @return array An array with content for the frequent terms markers
  */
 protected function getSearchTermMarkerProperties(array $frequentSearchTerms)
 {
     $frequentSearches = array();
     $minimumSize = $this->configuration['search.']['frequentSearches.']['minSize'];
     $maximumSize = $this->configuration['search.']['frequentSearches.']['maxSize'];
     if (count($frequentSearchTerms)) {
         $maximumHits = max(array_values($frequentSearchTerms));
         $minimumHits = min(array_values($frequentSearchTerms));
         $spread = $maximumHits - $minimumHits;
         $step = $spread == 0 ? 1 : ($maximumSize - $minimumSize) / $spread;
         foreach ($frequentSearchTerms as $term => $hits) {
             $size = round($minimumSize + ($hits - $minimumHits) * $step);
             $frequentSearches[] = array('term' => Tx_Solr_Template::escapeMarkers($term), 'hits' => $hits, 'style' => 'font-size: ' . $size . 'px', 'class' => 'tx-solr-frequent-term-' . $size, 'parameters' => '&q=' . html_entity_decode($term, ENT_NOQUOTES, 'UTF-8'), 'pid' => $this->parentPlugin->getLinkTargetPageId());
         }
     }
     return $frequentSearches;
 }
 /**
  * takes a search result document and processes its fields according to the
  * instructions configured in TS. Currently available instructions are
  * 	* timestamp - converts a date field into a unix timestamp
  * 	* serialize - uses serialize() to encode multivalue fields which then can be put out using the MULTIVALUE view helper
  * 	* skip - skips the whole field so that it is not available in the result, usefull for the spell field f.e.
  * The default is to do nothing and just add the document's field to the
  * resulting array.
  *
  * @param	Apache_Solr_Document	$document the Apache_Solr_Document result document
  * @return	array	An array with field values processed like defined in TS
  */
 protected function processDocumentFieldsToArray(Apache_Solr_Document $document)
 {
     $processingInstructions = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['results.']['fieldProcessingInstructions.'];
     $availableFields = $document->getFieldNames();
     $result = array();
     foreach ($availableFields as $fieldName) {
         $processingInstruction = $processingInstructions[$fieldName];
         // TODO switch to field processors
         // TODO allow to have multiple (commaseparated) instructions for each field
         switch ($processingInstruction) {
             case 'timestamp':
                 $processedFieldValue = Tx_Solr_Util::isoToTimestamp($document->{$fieldName});
                 break;
             case 'serialize':
                 if (!empty($document->{$fieldName})) {
                     $processedFieldValue = serialize($document->{$fieldName});
                 } else {
                     $processedFieldValue = '';
                 }
                 break;
             case 'skip':
                 continue 2;
             default:
                 $processedFieldValue = $document->{$fieldName};
         }
         // escape markers in document fields
         // TODO remove after switching to fluid templates
         $processedFieldValue = Tx_Solr_Template::escapeMarkers($processedFieldValue);
         $result[$fieldName] = $processedFieldValue;
     }
     return $result;
 }