TASK: Add another two processors

This commit is contained in:
Daniel Siepmann 2017-12-21 17:08:04 +01:00
parent a16bc2a60b
commit 0307471cf6
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 76 additions and 7 deletions

View file

@ -33,13 +33,6 @@ class ExplodeProcessor implements ProcessorInterface
$configuration['delimiter'] = ' '; $configuration['delimiter'] = ' ';
} }
if (is_array($record[$configuration['field']])) {
$record[$configuration['field']] = implode(
$configuration['delimiter'],
$record[$configuration['field']]
);
}
$record[$configuration['field']] = GeneralUtility::trimExplode( $record[$configuration['field']] = GeneralUtility::trimExplode(
$configuration['delimiter'], $configuration['delimiter'],
$record[$configuration['field']], $record[$configuration['field']],

View file

@ -0,0 +1,42 @@
<?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.
*/
/**
* Execute a regular expression replacement.
*/
class ReplaceProcessor implements ProcessorInterface
{
public function processRecord(array $record, array $configuration)
{
if (!isset($configuration['replacement'])) {
$configuration['replacement'] = ' ';
}
$record[$configuration['field']] = preg_replace(
$configuration['regularExpression'],
$configuration['replacement'],
$record[$configuration['field']]
);
return $record;
}
}

View file

@ -0,0 +1,34 @@
<?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.
*/
/**
* Execute on a single field to make entries unique.
*/
class UniqueProcessor implements ProcessorInterface
{
public function processRecord(array $record, array $configuration)
{
$record[$configuration['field']] = array_values(array_unique($record[$configuration['field']]));
return $record;
}
}