mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-25 09:16:12 +01:00
Merge pull request #95 from Codappix/feature/dataprocessor-remove
FEATURE: Add data processor to remove fields for indexing
This commit is contained in:
commit
ea8eb8148e
4 changed files with 201 additions and 0 deletions
44
Classes/DataProcessing/RemoveProcessor.php
Normal file
44
Classes/DataProcessing/RemoveProcessor.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
namespace Codappix\SearchCore\DataProcessing;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes fields from record.
|
||||||
|
*/
|
||||||
|
class RemoveProcessor implements ProcessorInterface
|
||||||
|
{
|
||||||
|
public function processRecord(array $record, array $configuration) : array
|
||||||
|
{
|
||||||
|
if (!isset($configuration['fields'])) {
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (GeneralUtility::trimExplode(',', $configuration['fields'], true) as $field) {
|
||||||
|
if (array_key_exists($field, $record)) {
|
||||||
|
unset($record[$field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
``Codappix\SearchCore\DataProcessing\RemoveProcessor``
|
||||||
|
======================================================
|
||||||
|
|
||||||
|
Will remove fields from record, e.g. if you do not want to sent them to elasticsearch at all.
|
||||||
|
|
||||||
|
Possible Options:
|
||||||
|
|
||||||
|
``fields``
|
||||||
|
Comma separated list of fields to remove from record.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
plugin.tx_searchcore.settings.indexing.tt_content.dataProcessing {
|
||||||
|
1 = Codappix\SearchCore\DataProcessing\RemoveProcessor
|
||||||
|
1 {
|
||||||
|
fields = description
|
||||||
|
}
|
||||||
|
2 = Codappix\SearchCore\DataProcessing\RemoveProcessor
|
||||||
|
2 {
|
||||||
|
fields = description, another_field
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -180,6 +180,7 @@ The following Processor are available:
|
||||||
:glob:
|
:glob:
|
||||||
|
|
||||||
dataProcessing/CopyToProcessor
|
dataProcessing/CopyToProcessor
|
||||||
|
dataProcessing/RemoveProcessor
|
||||||
dataProcessing/GeoPointProcessor
|
dataProcessing/GeoPointProcessor
|
||||||
|
|
||||||
The following Processor are planned:
|
The following Processor are planned:
|
||||||
|
|
133
Tests/Unit/DataProcessing/RemoveProcessorTest.php
Normal file
133
Tests/Unit/DataProcessing/RemoveProcessorTest.php
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
<?php
|
||||||
|
namespace Codappix\SearchCore\Tests\Unit\DataProcessing;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Codappix\SearchCore\DataProcessing\RemoveProcessor;
|
||||||
|
use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase;
|
||||||
|
|
||||||
|
class RemoveProcessorTest extends AbstractUnitTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @dataProvider getPossibleRecordConfigurationCombinations
|
||||||
|
*/
|
||||||
|
public function fieldsAreCopiedAsConfigured(array $record, array $configuration, array $expectedRecord)
|
||||||
|
{
|
||||||
|
$subject = new RemoveProcessor();
|
||||||
|
$processedRecord = $subject->processRecord($record, $configuration);
|
||||||
|
$this->assertSame(
|
||||||
|
$expectedRecord,
|
||||||
|
$processedRecord,
|
||||||
|
'The processor did not return the expected processed record.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getPossibleRecordConfigurationCombinations()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Nothing configured' => [
|
||||||
|
'record' => [
|
||||||
|
'field 1' => 'Some content like lorem',
|
||||||
|
'field with sub2' => [
|
||||||
|
'Tag 1',
|
||||||
|
'Tag 2',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'configuration' => [
|
||||||
|
],
|
||||||
|
'expectedRecord' => [
|
||||||
|
'field 1' => 'Some content like lorem',
|
||||||
|
'field with sub2' => [
|
||||||
|
'Tag 1',
|
||||||
|
'Tag 2',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'Single field configured' => [
|
||||||
|
'record' => [
|
||||||
|
'field 1' => 'Some content like lorem',
|
||||||
|
'field with sub2' => [
|
||||||
|
'Tag 1',
|
||||||
|
'Tag 2',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'configuration' => [
|
||||||
|
'fields' => 'field with sub2',
|
||||||
|
'_typoScriptNodeValue' => 'Codappix\SearchCore\DataProcessing\RemoveProcessor',
|
||||||
|
],
|
||||||
|
'expectedRecord' => [
|
||||||
|
'field 1' => 'Some content like lorem',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'Non existing field configured' => [
|
||||||
|
'record' => [
|
||||||
|
'field 1' => 'Some content like lorem',
|
||||||
|
'field with sub2' => [
|
||||||
|
'Tag 1',
|
||||||
|
'Tag 2',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'configuration' => [
|
||||||
|
'fields' => 'non existing',
|
||||||
|
'_typoScriptNodeValue' => 'Codappix\SearchCore\DataProcessing\RemoveProcessor',
|
||||||
|
],
|
||||||
|
'expectedRecord' => [
|
||||||
|
'field 1' => 'Some content like lorem',
|
||||||
|
'field with sub2' => [
|
||||||
|
'Tag 1',
|
||||||
|
'Tag 2',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'Multiple fields configured' => [
|
||||||
|
'record' => [
|
||||||
|
'field 1' => 'Some content like lorem',
|
||||||
|
'field with sub2' => [
|
||||||
|
'Tag 1',
|
||||||
|
'Tag 2',
|
||||||
|
],
|
||||||
|
'field 3' => 'Some more like lorem',
|
||||||
|
],
|
||||||
|
'configuration' => [
|
||||||
|
'fields' => 'field 3, field with sub2',
|
||||||
|
'_typoScriptNodeValue' => 'Codappix\SearchCore\DataProcessing\RemoveProcessor',
|
||||||
|
],
|
||||||
|
'expectedRecord' => [
|
||||||
|
'field 1' => 'Some content like lorem',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'Fields with "null" san be removed' => [
|
||||||
|
'record' => [
|
||||||
|
'field 1' => null,
|
||||||
|
],
|
||||||
|
'configuration' => [
|
||||||
|
'fields' => 'field 1',
|
||||||
|
'_typoScriptNodeValue' => 'Codappix\SearchCore\DataProcessing\RemoveProcessor',
|
||||||
|
],
|
||||||
|
'expectedRecord' => [
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue