mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
save modifications in conf, and also write back to databoxes
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
@@ -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(
|
||||
|
@@ -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;
|
||||
|
@@ -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'] = [];
|
||||
|
Reference in New Issue
Block a user