mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +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\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use databox_descriptionStructure;
|
||||||
|
|
||||||
class SearchEngineController extends Controller
|
class SearchEngineController extends Controller
|
||||||
{
|
{
|
||||||
@@ -77,6 +78,16 @@ class SearchEngineController extends Controller
|
|||||||
*/
|
*/
|
||||||
private function saveElasticSearchOptions(ElasticsearchOptions $configuration)
|
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());
|
$this->getConf()->set(['main', 'search-engine', 'options'], $configuration->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -228,7 +228,8 @@ class SearchEngineServiceProvider implements ServiceProviderInterface
|
|||||||
});
|
});
|
||||||
|
|
||||||
$app['elasticsearch.options'] = $app->share(function ($app) {
|
$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())) {
|
if (empty($options->getIndexName())) {
|
||||||
$options->setIndexName(strtolower(sprintf('phraseanet_%s', str_replace(
|
$options->setIndexName(strtolower(sprintf('phraseanet_%s', str_replace(
|
||||||
|
@@ -652,7 +652,7 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
$aggs = [];
|
$aggs = [];
|
||||||
// technical aggregates (enable + optional limit)
|
// technical aggregates (enable + optional limit)
|
||||||
foreach (ElasticsearchOptions::getAggregableTechnicalFields() as $k => $f) {
|
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_DISABLED) {
|
||||||
if ($size === databox_field::FACET_NO_LIMIT) {
|
if ($size === databox_field::FACET_NO_LIMIT) {
|
||||||
$size = ESField::FACET_NO_LIMIT;
|
$size = ESField::FACET_NO_LIMIT;
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
namespace Alchemy\Phrasea\SearchEngine\Elastic;
|
namespace Alchemy\Phrasea\SearchEngine\Elastic;
|
||||||
|
|
||||||
|
use databox_field;
|
||||||
use igorw;
|
use igorw;
|
||||||
|
|
||||||
|
|
||||||
@@ -219,10 +220,24 @@ class ElasticsearchOptions
|
|||||||
$this->highlight = $highlight;
|
$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)
|
public function setAggregableField($key, $attributes)
|
||||||
{
|
{
|
||||||
$facets = $this->getAggregableFields();
|
$this->getAggregableFields(); // ensure facets exists
|
||||||
$facets[$key] = $attributes;
|
$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)
|
public function getAggregableField($key)
|
||||||
@@ -231,7 +246,10 @@ class ElasticsearchOptions
|
|||||||
return array_key_exists($key, $facets) ? $facets[$key] : null;
|
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'])) {
|
if(!array_key_exists('facets', $this->_customValues) || !is_array($this->_customValues['facets'])) {
|
||||||
$this->_customValues['facets'] = [];
|
$this->_customValues['facets'] = [];
|
||||||
|
Reference in New Issue
Block a user