diff --git a/lib/Alchemy/Phrasea/Controller/Admin/SearchEngineController.php b/lib/Alchemy/Phrasea/Controller/Admin/SearchEngineController.php index 8073027302..565c2d759b 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/SearchEngineController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/SearchEngineController.php @@ -17,6 +17,7 @@ use Alchemy\Phrasea\SearchEngine\Elastic\Structure\GlobalStructure; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use databox_descriptionStructure; class SearchEngineController extends Controller { @@ -77,6 +78,16 @@ class SearchEngineController extends Controller */ private function saveElasticSearchOptions(ElasticsearchOptions $configuration) { + // save to databoxes fields for backward compatibility (useless ?) + foreach($configuration->getAggregableFields() as $fname=>$aggregableField) { + foreach ($this->app->getDataboxes() as $databox) { + if(!is_null($f = $databox->get_meta_structure()->get_element_by_name($fname, databox_descriptionStructure::STRICT_COMPARE))) { + $f->set_aggregable($aggregableField['limit'])->save(); + } + } + } + + // save to conf $this->getConf()->set(['main', 'search-engine', 'options'], $configuration->toArray()); } diff --git a/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php index 58f77475a1..faddfae370 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php @@ -228,7 +228,8 @@ class SearchEngineServiceProvider implements ServiceProviderInterface }); $app['elasticsearch.options'] = $app->share(function ($app) { - $options = ElasticsearchOptions::fromArray($app['conf']->get(['main', 'search-engine', 'options'], [])); + $conf = $app['conf']->get(['main', 'search-engine', 'options'], []); + $options = ElasticsearchOptions::fromArray($conf); if (empty($options->getIndexName())) { $options->setIndexName(strtolower(sprintf('phraseanet_%s', str_replace( diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index 63d9ec108e..15482f31d4 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -652,7 +652,7 @@ class ElasticSearchEngine implements SearchEngineInterface $aggs = []; // technical aggregates (enable + optional limit) foreach (ElasticsearchOptions::getAggregableTechnicalFields() as $k => $f) { - $size = $this->options->getAggregableFieldLimit($k); + $size = $this->options->getAggregableFieldLimit('_'.$k); if ($size !== databox_field::FACET_DISABLED) { if ($size === databox_field::FACET_NO_LIMIT) { $size = ESField::FACET_NO_LIMIT; diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchOptions.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchOptions.php index d65221dc8f..14ed77d008 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchOptions.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchOptions.php @@ -9,6 +9,7 @@ */ namespace Alchemy\Phrasea\SearchEngine\Elastic; +use databox_field; use igorw; @@ -219,10 +220,24 @@ class ElasticsearchOptions $this->highlight = $highlight; } + public function setAggregableFieldLimit($key, $value) + { + if(is_null($this->getAggregableField($key))) { + $this->_customValues['facets'][$key] = []; + } + $this->_customValues['facets'][$key]['limit'] = $value; + } + public function setAggregableField($key, $attributes) { - $facets = $this->getAggregableFields(); - $facets[$key] = $attributes; + $this->getAggregableFields(); // ensure facets exists + $this->_customValues['facets'][$key] = $attributes; + } + + public function getAggregableFieldLimit($key) + { + $facet = $this->getAggregableField($key); + return (is_array($facet) && array_key_exists('limit', $facet)) ? $facet['limit'] : databox_field::FACET_DISABLED; } public function getAggregableField($key) @@ -231,7 +246,10 @@ class ElasticsearchOptions return array_key_exists($key, $facets) ? $facets[$key] : null; } - public function &getAggregableFields() + /** + * @return array + */ + public function getAggregableFields() { if(!array_key_exists('facets', $this->_customValues) || !is_array($this->_customValues['facets'])) { $this->_customValues['facets'] = [];