mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 08:16:11 +01:00
FEATURE: Add data processor to remove fields for indexing
Add a new processor, with docs and tests, to allow removal of fields before sending them to search service like elasticsearch. E.g. remove sensitive information that should not be available.
This commit is contained in:
parent
43ec410eb5
commit
0159315183
4 changed files with 190 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 (isset($record[$field])) {
|
||||
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\CopyToProcessor
|
||||
2 {
|
||||
fields = description, another_field
|
||||
}
|
||||
}
|
||||
|
|
@ -180,6 +180,7 @@ The following Processor are available:
|
|||
:glob:
|
||||
|
||||
dataProcessing/CopyToProcessor
|
||||
dataProcessing/RemoveProcessor
|
||||
dataProcessing/GeoPointProcessor
|
||||
|
||||
The following Processor are planned:
|
||||
|
|
122
Tests/Unit/DataProcessing/RemoveProcessorTest.php
Normal file
122
Tests/Unit/DataProcessing/RemoveProcessorTest.php
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?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',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue