/**
  * Test if building the teaser works correct
  * @test
  */
 public function checkBuildTeaserContent()
 {
     $lib = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_kesearch_lib');
     $lib->conf['resultChars'] = 300;
     $lib->swords = array('Abgangszeugnis');
     $lib->cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tslib_cObj');
     $sr = new tx_kesearch_lib_searchresult($lib);
     // test without highlighting
     $result = $sr->buildTeaserContent($this->content);
     $resultShouldBe = '... Fächer). Es werden zentral einheitliche Prüfungen durchgeführt. Bei Zensuren in wenigstens zwölf Fächern nicht unter der Note 4 berechtigt das Abgangszeugnis der zwölften Klasse zum Studium an Universitäten und Hochschulen. Die in Lettland seit 1999 an der allgemeinbildenden oberen Sekundarstufe...';
     // in some cases there are many spaces one after the other which makes this assertion fail.
     // That's why I replace them with single spaces
     $result = preg_replace('/[ ]+/', ' ', $result);
     $resultShouldBe = preg_replace('/[ ]+/', ' ', $resultShouldBe);
     $this->assertEquals($resultShouldBe, $result);
     // test with highlighting
     $lib->conf['highlightSword'] = true;
     $result = $sr->buildTeaserContent($this->content);
     $resultShouldBe = '... Fächer). Es werden zentral einheitliche Prüfungen durchgeführt. Bei Zensuren in wenigstens zwölf Fächern nicht unter der Note 4 berechtigt das Abgangszeugnis der zwölften Klasse zum Studium an Universitäten und Hochschulen. Die in Lettland seit 1999 an der allgemeinbildenden oberen Sekundarstufe...';
     // in some cases there are many spaces one after the other which makes this assertion fail.
     // That's why I replace them with single spaces
     $result = preg_replace('/[ ]+/', ' ', $result);
     $resultShouldBe = preg_replace('/[ ]+/', ' ', $resultShouldBe);
     $this->assertEquals($resultShouldBe, $result);
 }
 /**
  * creates the search result list
  * 1. does the actual searching (fetches the results to $rows)
  * 2. fills fluid variables for fluid templates to $this->fluidTemplateVariables
  *
  */
 public function getSearchResults()
 {
     // fetch the search results
     $limit = $this->db->getLimit();
     $rows = $this->db->getSearchResults();
     // TODO: Check how Sphinx handles this, seems to return full result set
     if (count($rows) > $limit[1]) {
         $rows = array_slice($rows, $limit[0], $limit[1]);
     }
     // set number of results
     $this->numberOfResults = $this->db->getAmountOfSearchResults();
     // count searchword with ke_stats
     $this->countSearchWordWithKeStats($this->sword);
     // count search phrase in ke_search statistic tables
     if ($this->conf['countSearchPhrases']) {
         $this->countSearchPhrase($this->sword, $this->swords, $this->numberOfResults, $this->tagsAgainst);
     }
     // render "no results" text and stop here
     if ($this->numberOfResults == 0) {
         return $this->setNoResultsText();
     }
     // set switch for too short words
     $this->fluidTemplateVariables['wordsTooShort'] = $this->hasTooShortWords ? 1 : 0;
     // init counter and loop through the search results
     $resultCount = 1;
     $this->searchResult = GeneralUtility::makeInstance('tx_kesearch_lib_searchresult', $this);
     $this->fluidTemplateVariables['resultrows'] = array();
     foreach ($rows as $row) {
         $this->searchResult->setRow($row);
         $tempMarkerArray = array('orig_uid' => $row['orig_uid'], 'orig_pid' => $row['orig_pid'], 'title' => $this->searchResult->getTitle(), 'teaser' => $this->searchResult->getTeaser());
         // hook for additional markers in result row
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalResultMarker'])) {
             // make curent row number available to hook
             $this->currentRowNumber = $resultCount;
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalResultMarker'] as $_classRef) {
                 $_procObj =& GeneralUtility::getUserObj($_classRef);
                 $_procObj->additionalResultMarker($tempMarkerArray, $row, $this);
             }
             unset($this->currentRowNumber);
         }
         // add type marker
         // for file results just use the "file" type, not the file extension (eg. "file:pdf")
         list($type) = explode(':', $row['type']);
         $tempMarkerArray['type'] = str_replace(' ', '_', $type);
         // use the markers array as a base for the fluid template values
         $resultrowTemplateValues = $tempMarkerArray;
         // set result url
         $resultUrl = $this->searchResult->getResultUrl($this->conf['renderResultUrlAsLink']);
         $resultrowTemplateValues['url'] = $resultUrl;
         // set result numeration
         $resultNumber = $resultCount + $this->piVars['page'] * $this->conf['resultsPerPage'] - $this->conf['resultsPerPage'];
         $resultrowTemplateValues['number'] = $resultNumber;
         // set score (used for plain score output and score scale)
         $resultScore = number_format($row['score'], 2, ',', '');
         $resultrowTemplateValues['score'] = $resultScore;
         // set date (formatted and raw as a timestamp)
         $resultDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $row['sortdate']);
         $resultrowTemplateValues['date'] = $resultDate;
         $resultrowTemplateValues['date_timestamp'] = $row['sortdate'];
         // set percental score
         $resultrowTemplateValues['percent'] = $row['percent'];
         // show tags?
         $tags = $row['tags'];
         $tags = str_replace('#', ' ', $tags);
         $resultrowTemplateValues['tags'] = $tags;
         // set preview image
         $renderedImage = $this->renderPreviewImageOrTypeIcon($row);
         $resultrowTemplateValues['imageHtml'] = $renderedImage;
         // set end date for cal events
         if ($type == 'cal') {
             $resultrowTemplateValues['cal'] = $this->getCalEventEnddate($row['orig_uid']);
         }
         // add result row to the variables array
         $this->fluidTemplateVariables['resultrows'][] = $resultrowTemplateValues;
         // increase result counter
         $resultCount++;
     }
 }
Exemplo n.º 3
0
 /**
  * creates the search result list
  * 1. does the actual searching (fetches the results to $rows)
  * 2. fills the marker for marker based templating and renders the resultlist
  * 3. fills fluid variables for fluid based templating to $this->fluidTemplateVariables
  *
  * @return string rendered searchbox (for static or ajax templating, not for fluid templating)
  */
 public function getSearchResults()
 {
     // generate and add onload image
     $this->onloadImage = $this->createHideSpinner();
     // fetch the search results
     $limit = $this->db->getLimit();
     $rows = $this->db->getSearchResults();
     // TODO: Check how Sphinx handles this, seems to return full result set
     if (count($rows) > $limit[1]) {
         $rows = array_slice($rows, $limit[0], $limit[1]);
     }
     // set number of results
     $this->numberOfResults = $this->db->getAmountOfSearchResults();
     // count searchword with ke_stats
     $this->countSearchWordWithKeStats($this->sword);
     // count search phrase in ke_search statistic tables
     if ($this->conf['countSearchPhrases']) {
         $this->countSearchPhrase($this->sword, $this->swords, $this->numberOfResults, $this->tagsAgainst);
     }
     // render "no results" text and stop here
     if ($this->numberOfResults == 0) {
         return $this->renderNoResultsText();
     }
     if ($this->hasTooShortWords) {
         $content = $this->renderTooShortWordsText();
         $this->fluidTemplateVariables['wordsTooShort'] = 1;
     }
     // init counter and loop through the search results
     $resultCount = 1;
     $this->searchResult = GeneralUtility::makeInstance('tx_kesearch_lib_searchresult', $this);
     $this->fluidTemplateVariables['resultrows'] = array();
     foreach ($rows as $row) {
         // generate row content
         $tempContent = $this->cObj->getSubpart($this->templateCode, '###RESULT_ROW###');
         $this->searchResult->setRow($row);
         $tempMarkerArray = array('title' => $this->searchResult->getTitle(), 'teaser' => $this->searchResult->getTeaser());
         // hook for additional markers in result (only valid for maker based templating)
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalResultMarker'])) {
             // make curent row number available to hook
             $this->currentRowNumber = $resultCount;
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalResultMarker'] as $_classRef) {
                 $_procObj =& GeneralUtility::getUserObj($_classRef);
                 $_procObj->additionalResultMarker($tempMarkerArray, $row, $this);
             }
             unset($this->currentRowNumber);
         }
         // add type marker
         // for file results just use the "file" type, not the file extension (eg. "file:pdf")
         list($type) = explode(':', $row['type']);
         $tempMarkerArray['type'] = str_replace(' ', '_', $type);
         // replace markers
         $tempContent = $this->cObj->substituteMarkerArray($tempContent, $tempMarkerArray, $wrap = '###|###', $uppercase = 1);
         $resultrowTemplateValues = $tempMarkerArray;
         // show result url?
         $resultUrl = $this->searchResult->getResultUrl($this->conf['renderResultUrlAsLink']);
         if ($this->conf['showResultUrl']) {
             $subContent = $this->cObj->getSubpart($this->templateCode, '###SUB_RESULTURL###');
             $subContent = $this->cObj->substituteMarker($subContent, '###LABEL_RESULTURL###', $this->pi_getLL('label_resulturl'));
             $subContent = $this->cObj->substituteMarker($subContent, '###RESULTURL###', $resultUrl);
         } else {
             $subContent = '';
         }
         $tempContent = $this->cObj->substituteSubpart($tempContent, '###SUB_RESULTURL###', $subContent, $recursive = 1);
         $resultrowTemplateValues['url'] = $resultUrl;
         // show result numeration?
         $resultNumber = $resultCount + $this->piVars['page'] * $this->conf['resultsPerPage'] - $this->conf['resultsPerPage'];
         if ($this->conf['resultsNumeration']) {
             $subContent = $this->cObj->getSubpart($this->templateCode, '###SUB_NUMERATION###');
             $subContent = $this->cObj->substituteMarker($subContent, '###NUMBER###', $resultNumber);
         } else {
             $subContent = '';
         }
         $tempContent = $this->cObj->substituteSubpart($tempContent, '###SUB_NUMERATION###', $subContent, $recursive = 1);
         $resultrowTemplateValues['number'] = $resultNumber;
         // show score?
         $resultScore = number_format($row['score'], 2, ',', '');
         if ($this->conf['showScore'] && $row['score']) {
             $subContent = $this->cObj->getSubpart($this->templateCode, '###SUB_SCORE###');
             $subContent = $this->cObj->substituteMarker($subContent, '###LABEL_SCORE###', $this->pi_getLL('label_score'));
             $subContent = $this->cObj->substituteMarker($subContent, '###SCORE###', $resultScore);
         } else {
             $subContent = '';
         }
         $tempContent = $this->cObj->substituteSubpart($tempContent, '###SUB_SCORE###', $subContent, $recursive = 1);
         $resultrowTemplateValues['score'] = $resultScore;
         // show date?
         $resultDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $row['sortdate']);
         if ($this->conf['showDate'] && $row['sortdate']) {
             $subContent = $this->cObj->getSubpart($this->templateCode, '###SUB_DATE###');
             $subContent = $this->cObj->substituteMarker($subContent, '###LABEL_DATE###', $this->pi_getLL('label_date'));
             $subContent = $this->cObj->substituteMarker($subContent, '###DATE###', $resultDate);
         } else {
             $subContent = '';
         }
         $tempContent = $this->cObj->substituteSubpart($tempContent, '###SUB_DATE###', $subContent, $recursive = 1);
         $resultrowTemplateValues['date'] = $resultDate;
         // show percental score?
         if ($this->conf['showPercentalScore'] && $row['percent']) {
             $subContent = $this->cObj->getSubpart($this->templateCode, '###SUB_SCORE_PERCENT###');
             $subContent = $this->cObj->substituteMarker($subContent, '###LABEL_SCORE_PERCENT###', $this->pi_getLL('label_score_percent'));
             $subContent = $this->cObj->substituteMarker($subContent, '###SCORE_PERCENT###', $row['percent']);
         } else {
             $subContent = '';
         }
         $tempContent = $this->cObj->substituteSubpart($tempContent, '###SUB_SCORE_PERCENT###', $subContent, $recursive = 1);
         $resultrowTemplateValues['percent'] = $row['percent'];
         // show score scale?
         if ($this->conf['showScoreScale'] && $row['percent']) {
             $subContent = $this->cObj->getSubpart($this->templateCode, '###SUB_SCORE_SCALE###');
             $subContent = $this->cObj->substituteMarker($subContent, '###SCORE###', $row['percent']);
         } else {
             $subContent = '';
         }
         $tempContent = $this->cObj->substituteSubpart($tempContent, '###SUB_SCORE_SCALE###', $subContent, $recursive = 1);
         // show tags?
         $tags = $row['tags'];
         $tags = str_replace('#', ' ', $tags);
         if ($this->conf['showTags']) {
             $subContent = $this->cObj->getSubpart($this->templateCode, '###SUB_TAGS###');
             $subContent = $this->cObj->substituteMarker($subContent, '###LABEL_TAGS###', $this->pi_getLL('label_tags'));
             $subContent = $this->cObj->substituteMarker($subContent, '###TAGS###', htmlspecialchars($tags));
         } else {
             $subContent = '';
         }
         $tempContent = $this->cObj->substituteSubpart($tempContent, '###SUB_TAGS###', $subContent, $recursive = 1);
         $resultrowTemplateValues['tags'] = $tags;
         // preview image
         $renderedImage = $this->renderPreviewImageOrTypeIcon($row);
         $resultrowTemplateValues['imageHtml'] = $renderedImage[0];
         $tempContent = $this->cObj->substituteSubpart($tempContent, '###SUB_TYPE_ICON###', $renderedImage[1], $recursive = 1);
         // fluid templating: add result row to the variables array
         $this->fluidTemplateVariables['resultrows'][] = $resultrowTemplateValues;
         // marker based templating: add temp content to result list
         $content .= $tempContent;
         // increase result counter
         $resultCount++;
     }
     // hook for additional content AFTER the result list
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalContentAfterResultList'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['additionalContentAfterResultList'] as $_classRef) {
             $_procObj =& GeneralUtility::getUserObj($_classRef);
             $content .= $_procObj->additionalContentAfterResultList($this);
         }
     }
     // add onload image if in AJAX mode
     if ($this->conf['renderMethod'] != 'static') {
         $content .= $this->onloadImage;
     }
     return $content;
 }