BUGFIX: Fix nun working options due to miss match of ts and es

As TypoScript does not provide a way to configure key less options, we
use a comma separated list and explode them to stay compatible with
elasticsearch.
This commit is contained in:
Daniel Siepmann 2017-07-25 15:00:25 +02:00
parent 6462052c9b
commit c1cc16efa5
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 40 additions and 15 deletions

View file

@ -24,6 +24,7 @@ use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
use Codappix\SearchCore\Configuration\InvalidArgumentException; use Codappix\SearchCore\Configuration\InvalidArgumentException;
use Elastica\Exception\ResponseException; use Elastica\Exception\ResponseException;
use TYPO3\CMS\Core\SingletonInterface as Singleton; use TYPO3\CMS\Core\SingletonInterface as Singleton;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
/** /**
@ -67,14 +68,41 @@ class IndexFactory implements Singleton
/** /**
* @param string $documentType * @param string $documentType
*
* @return array * @return array
*/ */
protected function getConfigurationFor($documentType) protected function getConfigurationFor($documentType)
{ {
try { try {
return $this->configuration->get('indexing.' . $documentType . '.index'); $configuration = $this->configuration->get('indexing.' . $documentType . '.index');
if (isset($configuration['analysis']['analyzer'])) {
foreach ($configuration['analysis']['analyzer'] as $key => $analyzer) {
$configuration['analysis']['analyzer'][$key] = $this->prepareAnalyzerConfiguration($analyzer);
}
}
return $configuration;
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
return []; return [];
} }
} }
/**
* @param array $analyzer
*
* @return array
*/
protected function prepareAnalyzerConfiguration(array $analyzer)
{
$fieldsToExplode = ['char_filter', 'filter'];
foreach ($fieldsToExplode as $fieldToExplode) {
if (isset($analyzer[$fieldToExplode])) {
$analyzer[$fieldToExplode] = GeneralUtility::trimExplode(',', $analyzer[$fieldToExplode], true);
}
}
return $analyzer;
}
} }

View file

@ -201,13 +201,8 @@ options are available:
ngram4 { ngram4 {
type = custom type = custom
tokenizer = ngram4 tokenizer = ngram4
char_filter { char_filter = html_strip
html_strip filter = lowercase, asciifolding
}
filter {
lowercase
}
} }
} }
@ -221,6 +216,8 @@ options are available:
} }
} }
``char_filter`` and ``filter`` are a comma separated list of options.
.. _configuration_options_search: .. _configuration_options_search:
Searching Searching

View file

@ -81,12 +81,8 @@ class IndexFactoryTest extends AbstractUnitTestCase
'ngram4' => [ 'ngram4' => [
'type' => 'custom', 'type' => 'custom',
'tokenizer' => 'ngram4', 'tokenizer' => 'ngram4',
'char_filter' => [ 'char_filter' => 'html_strip',
'html_strip', 'filter' => 'lowercase, , asciifolding',
],
'filter' => [
'lowercase',
],
], ],
], ],
'tokenizer' => [ 'tokenizer' => [
@ -99,6 +95,10 @@ class IndexFactoryTest extends AbstractUnitTestCase
], ],
]; ];
$expectedConfiguration = $configuration;
$expectedConfiguration['analysis']['analyzer']['ngram4']['char_filter'] = ['html_strip'];
$expectedConfiguration['analysis']['analyzer']['ngram4']['filter'] = ['lowercase', 'asciifolding'];
$indexMock = $this->getMockBuilder(\Elastica\Index::class) $indexMock = $this->getMockBuilder(\Elastica\Index::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -107,7 +107,7 @@ class IndexFactoryTest extends AbstractUnitTestCase
->willReturn(false); ->willReturn(false);
$indexMock->expects($this->once()) $indexMock->expects($this->once())
->method('create') ->method('create')
->with($configuration); ->with($expectedConfiguration);
$clientMock = $this->getMockBuilder(\Elastica\Client::class) $clientMock = $this->getMockBuilder(\Elastica\Client::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();