Indexing extension records with “Indexing Configuration”

If we use “indexed_search” extension in TYPO3 then there are two ways to index extensions records. First one is to create “Crawler Configuration” records. The second one is to create “Indexing Configuration” records.

The “Crawler Configuration” has a drawback that is crawl all records in frontend so whole TYPO3 is run to generate a page with single view of record. The “Indexing Configuration” way scans only selected fields from record and based on that creates records on indexed_search tables.

Important notes:

  1. Remember to put the “Indexing Configuration” record on the page where single records are shown. Read later why.
  2. Remember to carefully choose the table to index from dropdown selector. Sometimes in project there are two the same tables titles but names of the tables are different in database.
  3. If you want to test if “Indexing Configuration” works well then install extension “crawlerx”. It will provide you nice CLI command that will cleanup the testing bed. It will truncate all related tables. Use it like:
    php ./typo3/cli_dispatch.phpsh extbase crawlerx:cleanfortest
    php ./typo3/cli_dispatch.phpsh crawler

While configuring  “Indexing Configuration” remember that configuration of some fields there is tricky. Here some tips:

  1. Field: “Alternative Source Page”
    By default the indexer will select records from the page id where the Indexing Configuration is stored. If you want an alternative page as the source of your records you can enter it here.
  2. Field: “Fields (first is title):
    Fields in table that will be indexed. The first field will be also a title of search result. If you have nested relations and want them to be searchable then use extension “fieldgenerator”. This extension will allow you to generate field content based on fields of record and his relations. The new field will be populated with content on record save (hoo afterDatabase).
    The best name for the field that you can extend your model for search reason is field “Keyword”. This field does not have to be visible in TCA so for TCA its enough to make it passthrough.This is example part of TCA with columns configuration:

            'keywords' => array(
                'config' => array(
                    'type' => 'passthrough',
                ),
            ),

    Here example of TCA configuration for new field generation:

            'fieldsGenerator' => [
                'repositoryClass' => Alfa\Recipes\Domain\Repository\RecipeRepository::class,
                'generate' => [
                    'keywords' => [
                        'fields' => 'name,sections.steps.description,sections.ingredients.name',
                    ]
                ]
            ],

    Here example property declaration and getter and setter in model class:

        /**
         * keywords
         *
         * @var string
         */
        protected $keywords = '';
    
    
    ........................
    
    
        /**
         * @return string
         */
        public function getKeywords() {
            return $this->keywords;
        }
    
        /**
         * @param string $keywords
         */
        public function setKeywords($keywords) {
            $this->keywords = $keywords;
        }

     

  3. Field: “GET parameter string”
    Here you create link to single record with availability to use ###UID### marker.
    Notes:
    – string must start with “&”,
    – the “id” parameter is not wotking. You can not force the page id! This is why remember to put the “Indexing Configuration” record on the page where single records are shown. This is only way to force page id.
    – by default no other markers are available except  ###UID###
    – if you need to use more markers from one record then you can use extension “crawlerx”.

    &tx_recipes_recipes[category]=###CATEGORY###&tx_recipes_recipes[recipe]=###UID###
    
  4. Field: “Index Records immediately when saved?
    Means that when you will edit the record to be indexed and save it then this record will be indexed at once. (hook processDatamap_afterDatabaseOperations is used)
  5. If the title contains special characters you can use the function preg_replace to replace these characters.
    For example:

            'fieldsGenerator' => [
                'repositoryClass' => Alfa\Recipes\Domain\Repository\RecipeRepository::class,
                'generate' => [
                    'keywords' => [
                        'fields' => 'name,sections.steps.description,sections.ingredients.name',
                        'preg_replace' => [
                            'pattern' => '/[:]/',
                            'replacement' => ''
                        ]
                    ]
                ]
            ],

    Otherwise the keywords may be incorrectly indexed.

 

Leave a Comment.