diff --git a/lib/Alchemy/Phrasea/Controller/Admin/SearchEngineController.php b/lib/Alchemy/Phrasea/Controller/Admin/SearchEngineController.php index 565c2d759b..04762b3aef 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/SearchEngineController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/SearchEngineController.php @@ -33,7 +33,19 @@ class SearchEngineController extends Controller $form->handleRequest($request); if ($form->isValid()) { - $this->saveElasticSearchOptions($form->getData()); + /** @var ElasticsearchOptions $data */ + $data = $form->getData(); + // $q = $request->request->get('elasticsearch_settings'); + $facetNames = []; // rebuild the data "_customValues/facets" list following the form order + foreach($request->request->get('elasticsearch_settings') as $name=>$value) { + $matches = null; + if(preg_match('/^facets:(.+):limit$/', $name, $matches) === 1) { + $facetNames[] = $matches[1]; + } + } + $data->reorderAggregableFields($facetNames); + + $this->saveElasticSearchOptions($data); return $this->app->redirectPath('admin_searchengine_form'); } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchOptions.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchOptions.php index b469af4d92..c471980752 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchOptions.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchOptions.php @@ -257,6 +257,18 @@ class ElasticsearchOptions return $this->_customValues['facets']; } + // set to change the facets order during admin/form save + public function reorderAggregableFields($facetNames) + { + $newFacets = []; + foreach ($facetNames as $name) { + if(($facet = $this->getAggregableField($name)) !== null) { + $newFacets[$name] = $facet; + } + } + $this->_customValues['facets'] = $newFacets; + } + public function getActiveTab() { return $this->activeTab;