diff --git a/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php index 3b4e271561..4216ce1b6b 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php @@ -59,7 +59,6 @@ class SearchEngineServiceProvider implements ServiceProviderInterface $app['elasticsearch.client'], $app['elasticsearch.options']['index'], $app['locales.available'], - $app['elasticsearch.record_helper'], $app['elasticsearch.facets_response.factory'] ); }); diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index b8dbdd383c..895a96b4b5 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -41,15 +41,13 @@ class ElasticSearchEngine implements SearchEngineInterface private $indexName; private $configurationPanel; private $locales; - private $recordHelper; - public function __construct(Application $app, Structure $structure, Client $client, $indexName, array $locales, RecordHelper $recordHelper, Closure $facetsResponseFactory) + public function __construct(Application $app, Structure $structure, Client $client, $indexName, array $locales, Closure $facetsResponseFactory) { $this->app = $app; $this->structure = $structure; $this->client = $client; $this->locales = array_keys($locales); - $this->recordHelper = $recordHelper; $this->facetsResponseFactory = $facetsResponseFactory; if ('' === trim($indexName)) { @@ -384,7 +382,7 @@ class ElasticSearchEngine implements SearchEngineInterface // 2015-05-26 (mdarse) Removed databox filtering. // It was already done by the ACL filter in the query scope, so no // document that shouldn't be displayed can go this far. - $field_name = RecordHelper::getIndexFieldName($field); + $field_name = $field->getIndexFieldName(); $aggs[$name]['terms']['field'] = sprintf('%s.raw', $field_name); } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/RecordHelper.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/RecordHelper.php index 7e4af313ce..3f26050870 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/RecordHelper.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/RecordHelper.php @@ -85,13 +85,4 @@ class RecordHelper return null; } } - - public static function getIndexFieldName(Field $field) - { - return sprintf( - '%scaption.%s', - $field->isPrivate() ? 'private_' : '', - $field->getName() - ); - } } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/QueryContext.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/QueryContext.php index ffeb19c924..64c136bb52 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/QueryContext.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/QueryContext.php @@ -34,7 +34,7 @@ class QueryContext } } - return new static($this->locales, $this->queryLocale, $fields); + return new static($this->structure, $this->locales, $this->queryLocale, $fields); } public function getRawFields() @@ -94,7 +94,7 @@ class QueryContext return; } // TODO Field label dereferencing (we only want names) - return RecordIndexer::getIndexFieldName($field); + return $field->getIndexFieldName(); } public function getFields() diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Field.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Field.php index 4de0385a16..85198d8788 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Field.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Field.php @@ -73,6 +73,15 @@ class Field return $this->name; } + public function getIndexFieldName() + { + return sprintf( + '%scaption.%s', + $this->is_private ? 'private_' : '', + $this->name + ); + } + public function getType() { return $this->type; diff --git a/tests/Alchemy/Tests/Phrasea/SearchEngine/Search/QueryContextTest.php b/tests/Alchemy/Tests/Phrasea/SearchEngine/Search/QueryContextTest.php new file mode 100644 index 0000000000..9740f30052 --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/SearchEngine/Search/QueryContextTest.php @@ -0,0 +1,33 @@ +prophesize(Structure::class)->reveal(); + $available_locales = ['ab', 'cd', 'ef']; + $context = new QueryContext($structure, $available_locales, 'fr'); + $narrowed = $context->narrowToFields(['some_field']); + $this->assertEquals(['some_field'], $narrowed->getFields()); + } + + public function testFieldNormalization() + { + $public_field = new Field('foo', Mapping::TYPE_STRING, true, false); + $restricted_field = new Field('bar', Mapping::TYPE_STRING, true, true); + $structure = $this->prophesize(Structure::class); + $structure->get('foo')->willReturn($public_field); + $structure->get('bar')->willReturn($restricted_field); + + $context = new QueryContext($structure->reveal(), [], 'fr'); + $this->assertEquals('caption.foo', $context->normalizeField('foo')); + $this->assertEquals('private_caption.bar', $context->normalizeField('bar')); + } +}