Zum Inhalt springen

ke_search: eigene Contentelemente indexieren

Erstellt am 28. März 2012 · 3 Antworten · letzte Antwort am 18. Juni 2014

Tags: Inhaltselemente, Suche, Frage

rookie_37 ·

Ich habe die Extension ke_search installiert und finde sie wirklich top!

Mein Problem ist nun aber, dass eigene Inhlatselemente nicht indexiert werden. Ich habe mir ein eigenes Inhaltselement "gebastelt", welches auch in die Tabelle tt_content schreibt, allerdings als Ctype "specialtext" verwendet. Diese Inhalte werden nicht nicht indexiert (text, textpic, shortcut aber schon).

Wie kann ich dem Indexer beibringen, das CType "detailtext" ebenfalls zu berücksichtigen?

rookie_37 ·

Wow, mehr als ein Jahr zu spät, habe diesen Post leider erst jetzt entdeckt :o
Vielen Dank, das war genau der Punkt.

mediew ·

Fall hier jemand drauf stößt.

Es gibt aktuell ein Feature-Request:

#58631: Make CTypes configurable
http://forge.typo3.org/issues/58631

Vorübergehend gibt es auch eine Lösung mittels eines eigenen Indexers.
ext_localconf.php:

<?php
// ...

// register custom indexer hook for EXT:ke_search
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['registerIndexerConfiguration'][]
    = 'EXT:' . $_EXTKEY . '/Classes/Hooks/KeSearchExtenedPagesIndexer.php:KeSearchExtenedPagesIndexer';

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['customIndexer'][]
    = 'EXT:' . $_EXTKEY . '/Classes/Hooks/KeSearchExtenedPagesIndexer.php:KeSearchExtenedPagesIndexer';

KeSearchExtenedPagesIndexer.php

<?php

/***************************************************************
 *  Copyright notice
 *
 *  (c) 2012 Christian Bülter (kennziffer.com) <buelter@kennziffer.com>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

class KeSearchExtenedPagesIndexer {

    /**
     * Adds the custom indexer to the TCA of indexer configurations, so that
     * it's selectable in the backend as an indexer type when you create a
     * new indexer configuration.
     *
     * @param array $params
     * @param type $pObj
     */
    function registerIndexerConfiguration(&$params, $pObj) {

        // add item to "type" field
        $newArray = array(
            'Extend pages',
            'extended_pages',
            \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('example') . 'Resources/Public/Icons/kesearch-indexer-extend_pages.gif'
        );
        $params['items'][] = $newArray;

        // enable fields in indexer config
        $GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['fileext']['displayCond'] .= ',extended_pages';
        $GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['index_content_with_restrictions']['displayCond'] .= ',extended_pages';
        $GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['index_use_page_tags_for_files']['displayCond'] .= ',extended_pages';
        $GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['single_pages']['displayCond'] .= ',extended_pages';
        $GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['startingpoints_recursive']['displayCond'] .= ',extended_pages';
        $GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['targetpid']['displayCond'] .= ',extended_pages';
        $GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['targetpid']['displayCond'] .= ',extended_pages';
    }

    /**
     * Custom indexer for ke_search
     *
     * @param   array $indexerConfig Configuration from TYPO3 Backend
     * @param   array $indexerObject Reference to indexer class.
     * @return  string Output.
     */
    public function customIndexer(&$indexerConfig, &$indexerObject) {
        if($indexerConfig['type'] == 'extended_pages') {
            $content = '';

            // Create new instance from tx_kesearch_indexer_types_page
            $keseachIndexerTypesPage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_kesearch_indexer_types_page');
            $keseachIndexerTypesPage->pObj = $indexerObject;
            $keseachIndexerTypesPage->indexerConfig = $indexerConfig;

            // Add own CTypes
            $ownCTypes = array(
                'example_1',
                'example_2',
                'example_3',
            );
            $keseachIndexerTypesPage->indexCTypes = array_merge($keseachIndexerTypesPage->indexCTypes, $ownCTypes);
            foreach ($keseachIndexerTypesPage->indexCTypes as $value) {
                $cTypes[] = 'CType="' . $value . '"';
            }
            $keseachIndexerTypesPage->whereClauseForCType = implode(' OR ', $cTypes);

            // Start indexing
            $content = $keseachIndexerTypesPage->startIndexing();

            return $content;
        }
    }
}