Ext: Indexed Search.

Viewhelper zur Darstellung des Newstitels auf der Suchergebnisseite

Problem:

Indexed Search geht die Seiten der Webseite durch und indexiert deren Inhalte. News-Artikel werden in der Standardkonfiguration nicht indexiert. Mit folgender CrawlerKonfiguration in der Page.ts kann indexed search aber auch News indexieren.

 

tx_crawler.crawlerCfg.paramSets {
  tx_news = &tx_news_pi1[news]=[_TABLE:tx_news_domain_model_news;_PID:{$plugin.tx_news.settings.startingpoint}]
  tx_news.procInstrFilter = tx_indexedsearch_reindex, tx_cachemgm_recache
  tx_news.cHash = 1
  tx_news.pidsOnly = {$plugin.tx_news.settings.singlePid}
}

 

Bei einem einzelnen News-Singlke-Ansicht kann die Konfiguration auch im Backend angelegt werden. Hier muss dann zusätzlich unter Configuration stehen:

 

&tx_news_pi1[news]=[_TABLE:tx_news_domain_model_news;_PID:{$plugin.tx_news.settings.startingpoint}]
#zusätzlich muss "Append cHash" aktiviert sein

 

Nun ergibt sich aber ein neues Problem. Die Suchergebnisse in der News werden über den Seitentitel gelistet. Der ist aber der Titel der SINGLE-Ansicht. Um hier den Titel der News darzustellen, habe ich einen Viewhelper erstellt.

EXT: fh_customviewhelpers/Classes/ViewHelpers/NewsidViewHelper.php

 

<?php
namespace Fischhase\FhCustomviewhelpers\ViewHelpers;

use TYPO3\CMS\Core\Database\DatabaseConnection;

class NewsidViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

    /**
    * Parses NewsID from cHash
    * sends to Database query for Newstitle
    * Usage z.B. indexed Search Searchresult.html: <fh:newsid cHash="{row.cHashParams}" pageTitle="{row.title -> f:format.raw()}" />
    **/

     /**
     * @return DatabaseConnection
     */
    protected function getDatabaseConnection()
    {
        return $GLOBALS['TYPO3_DB'];
    }

    /**
    * @param string $cHash
    * @param string $pageTitle
    * @return string
    **/

    public function render($cHash = NULL, $pageTitle = "") {
        if ($cHash === NULL) {
            $cHash = $this->renderChildren();
        }

        if( preg_match ('/{(.*)}/', $cHash, $result_string)) {
            $result_array = explode (';',$result_string[1]);
            $return_array = [];
            for ($i=0; $i<=count ($result_array); $i=$i+2) {
                $tmp_key = explode ('"',$result_array[$i])[1];

                $tmp_key = str_replace("[", "_", $tmp_key);
                $tmp_key = str_replace("]", "", $tmp_key);

                $return_array[$tmp_key] = explode ('"',$result_array[$i+1])[1];
            }
        }

        $retvalue = $this->getNewsTitle((int)$return_array[tx_news_pi1_news]);
        if (!$retvalue) $retvalue = $pageTitle;
        return $retvalue;
    }

    /**
    * Returns the title of news
    *
    * @param int $NewsUid
    * @return mixed
    */
    protected function getNewsTitle($NewsUid) {
        $NewsUid = (int)$NewsUid;
        if($NewsUid > 0) {
            $db = $this->getDatabaseConnection();
            $result = $db->exec_SELECTgetSingleRow('title', 'tx_news_domain_model_news', 'uid = ' . (int)$NewsUid);
            return $result['title'];
        } else {
            return false;
        }
    }

}
?>