mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-25 11:56:10 +01:00
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:
parent
6462052c9b
commit
c1cc16efa5
3 changed files with 40 additions and 15 deletions
|
@ -24,6 +24,7 @@ use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
|
|||
use Codappix\SearchCore\Configuration\InvalidArgumentException;
|
||||
use Elastica\Exception\ResponseException;
|
||||
use TYPO3\CMS\Core\SingletonInterface as Singleton;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||
|
||||
/**
|
||||
|
@ -67,14 +68,41 @@ class IndexFactory implements Singleton
|
|||
|
||||
/**
|
||||
* @param string $documentType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getConfigurationFor($documentType)
|
||||
{
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,13 +201,8 @@ options are available:
|
|||
ngram4 {
|
||||
type = custom
|
||||
tokenizer = ngram4
|
||||
char_filter {
|
||||
html_strip
|
||||
}
|
||||
|
||||
filter {
|
||||
lowercase
|
||||
}
|
||||
char_filter = html_strip
|
||||
filter = lowercase, asciifolding
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,6 +216,8 @@ options are available:
|
|||
}
|
||||
}
|
||||
|
||||
``char_filter`` and ``filter`` are a comma separated list of options.
|
||||
|
||||
.. _configuration_options_search:
|
||||
|
||||
Searching
|
||||
|
|
|
@ -81,12 +81,8 @@ class IndexFactoryTest extends AbstractUnitTestCase
|
|||
'ngram4' => [
|
||||
'type' => 'custom',
|
||||
'tokenizer' => 'ngram4',
|
||||
'char_filter' => [
|
||||
'html_strip',
|
||||
],
|
||||
'filter' => [
|
||||
'lowercase',
|
||||
],
|
||||
'char_filter' => 'html_strip',
|
||||
'filter' => 'lowercase, , asciifolding',
|
||||
],
|
||||
],
|
||||
'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)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -107,7 +107,7 @@ class IndexFactoryTest extends AbstractUnitTestCase
|
|||
->willReturn(false);
|
||||
$indexMock->expects($this->once())
|
||||
->method('create')
|
||||
->with($configuration);
|
||||
->with($expectedConfiguration);
|
||||
$clientMock = $this->getMockBuilder(\Elastica\Client::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
|
Loading…
Reference in a new issue