!!!|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.
This commit is contained in:
Daniel Siepmann 2017-12-19 17:02:18 +01:00
parent cc275d1f32
commit 0716b5a3d2
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
6 changed files with 23 additions and 53 deletions

View file

@ -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.
}
}

View file

@ -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'];
}

View file

@ -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
}
}
}
}
}

View file

@ -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.<identifier>.abstractFields := addToList(content)
Default::
abstract, description, bodytext
.. _mapping:
``mapping``

View file

@ -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`.

View file

@ -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
}
}
}
}