From 0716b5a3d266b4e38b5186e99c492b8edd70d164 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 19 Dec 2017 17:02:18 +0100 Subject: [PATCH] !!!|TASK: Replace abstractFields with CopyToProcessor Do not implement feature with custom code, but use existing feature to create search_abstract field. Also execute DataProcessing in AbstractIndexer, not in TcaTableService, to affect all current available indexers, not only some. Also this is the place to be. --- Classes/Domain/Index/AbstractIndexer.php | 24 +++++++------------ .../Index/TcaIndexer/TcaTableService.php | 13 ---------- Configuration/TypoScript/setup.txt | 8 ++++++- Documentation/source/configuration.rst | 20 ---------------- Documentation/source/indexer.rst | 2 -- Tests/Functional/Fixtures/BasicSetup.ts | 9 ++++++- 6 files changed, 23 insertions(+), 53 deletions(-) diff --git a/Classes/Domain/Index/AbstractIndexer.php b/Classes/Domain/Index/AbstractIndexer.php index 143a219..e5e32dc 100644 --- a/Classes/Domain/Index/AbstractIndexer.php +++ b/Classes/Domain/Index/AbstractIndexer.php @@ -21,8 +21,9 @@ namespace Codappix\SearchCore\Domain\Index; */ use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; -use Codappix\SearchCore\Configuration\InvalidArgumentException; +use Codappix\SearchCore\Configuration\InvalidArgumentException as InvalidConfigurationArgumentException; use Codappix\SearchCore\Connection\ConnectionInterface; +use Codappix\SearchCore\DataProcessing\ProcessorInterface; use \TYPO3\CMS\Core\Utility\GeneralUtility; abstract class AbstractIndexer implements IndexerInterface @@ -123,24 +124,15 @@ abstract class AbstractIndexer implements IndexerInterface */ protected function prepareRecord(array &$record) { - $record['search_abstract'] = ''; - try { - $fieldsToUse = GeneralUtility::trimExplode( - ',', - $this->configuration->get('indexing.' . $this->identifier . '.abstractFields') - ); - if (!$fieldsToUse) { - return; - } - foreach ($fieldsToUse as $fieldToUse) { - if (isset($record[$fieldToUse]) && trim($record[$fieldToUse])) { - $record['search_abstract'] = trim($record[$fieldToUse]); - break; + foreach ($this->configuration->get('indexing.' . $this->identifier . '.dataProcessing') as $configuration) { + $dataProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($configuration['_typoScriptNodeValue']); + if ($dataProcessor instanceof ProcessorInterface) { + $record = $dataProcessor->processRecord($record, $configuration); } } - } catch (InvalidArgumentException $e) { - return; + } catch (InvalidConfigurationArgumentException $e) { + // Nothing to do. } } diff --git a/Classes/Domain/Index/TcaIndexer/TcaTableService.php b/Classes/Domain/Index/TcaIndexer/TcaTableService.php index e68a94f..70bb52d 100644 --- a/Classes/Domain/Index/TcaIndexer/TcaTableService.php +++ b/Classes/Domain/Index/TcaIndexer/TcaTableService.php @@ -21,8 +21,6 @@ namespace Codappix\SearchCore\Domain\Index\TcaIndexer; */ use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; -use Codappix\SearchCore\Configuration\InvalidArgumentException as InvalidConfigurationArgumentException; -use Codappix\SearchCore\DataProcessing\ProcessorInterface; use Codappix\SearchCore\Domain\Index\IndexingException; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -150,17 +148,6 @@ class TcaTableService { $this->relationResolver->resolveRelationsForRecord($this, $record); - try { - foreach ($this->configuration->get('indexing.' . $this->tableName . '.dataProcessing') as $configuration) { - $dataProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($configuration['_typoScriptNodeValue']); - if ($dataProcessor instanceof ProcessorInterface) { - $record = $dataProcessor->processRecord($record, $configuration); - } - } - } catch (InvalidConfigurationArgumentException $e) { - // Nothing to do. - } - if (isset($record['uid']) && !isset($record['search_identifier'])) { $record['search_identifier'] = $record['uid']; } diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt index 67612e1..0941ba9 100644 --- a/Configuration/TypoScript/setup.txt +++ b/Configuration/TypoScript/setup.txt @@ -18,7 +18,13 @@ plugin { pages { indexer = Codappix\SearchCore\Domain\Index\TcaIndexer\PagesIndexer additionalWhereClause = {$plugin.tx_searchcore.settings.indexing.pages.additionalWhereClause} - abstractFields = {$plugin.tx_searchcore.settings.indexing.pages.abstractFields} + dataProcessing { + 0 = Codappix\SearchCore\DataProcessing\CopyToProcessor + 0 { + from = {$plugin.tx_searchcore.settings.indexing.pages.abstractFields} + to = search_abstract + } + } } } } diff --git a/Documentation/source/configuration.rst b/Documentation/source/configuration.rst index 549ca68..7a11d84 100644 --- a/Documentation/source/configuration.rst +++ b/Documentation/source/configuration.rst @@ -162,26 +162,6 @@ options are available: Make sure to prefix all fields with the corresponding table name. The selection from database will contain joins and can lead to SQL errors if a field exists in multiple tables. -.. _abstractFields: - -``abstractFields`` -""""""""""""""""""""""""" - - Used by: :ref:`PagesIndexer`. - - Define which field should be used to provide the auto generated field "search_abstract". - The fields have to exist in the record to be indexed. Therefore fields like ``content`` are also - possible. - - Example:: - - # As last fallback we use the content of the page - plugin.tx_searchcore.settings.indexing..abstractFields := addToList(content) - - Default:: - - abstract, description, bodytext - .. _mapping: ``mapping`` diff --git a/Documentation/source/indexer.rst b/Documentation/source/indexer.rst index ddc6772..4f225d0 100644 --- a/Documentation/source/indexer.rst +++ b/Documentation/source/indexer.rst @@ -48,8 +48,6 @@ The indexer is configurable through the following options: * :ref:`additionalWhereClause` -* :ref:`abstractFields` - .. note:: Not all relations are resolved yet, see :issue:`17` and :pr:`20`. diff --git a/Tests/Functional/Fixtures/BasicSetup.ts b/Tests/Functional/Fixtures/BasicSetup.ts index 9795b0f..f10d932 100644 --- a/Tests/Functional/Fixtures/BasicSetup.ts +++ b/Tests/Functional/Fixtures/BasicSetup.ts @@ -26,13 +26,20 @@ plugin { pages { indexer = Codappix\SearchCore\Domain\Index\TcaIndexer\PagesIndexer - abstractFields = abstract, description, bodytext mapping { CType { type = keyword } } + + dataProcessing { + 0 = Codappix\SearchCore\DataProcessing\CopyToProcessor + 0 { + from = abstract, description, bodytext + to = search_abstract + } + } } }