mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
PHRAS-2815_generate-cterms-multi-db_4.1
fix : the "generate cterms" setting is applied by db how : the "global_structure" (fields merged) now also contains field settings by db
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\SearchEngine\Elastic\Indexer\Record\Hydrator;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Exception\Exception;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\GlobalStructure;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\CandidateTerms;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\Concept;
|
||||
@@ -27,7 +28,7 @@ class ThesaurusHydrator implements HydratorInterface
|
||||
private $thesaurus;
|
||||
private $candidate_terms;
|
||||
|
||||
public function __construct(Structure $structure, Thesaurus $thesaurus, CandidateTerms $candidate_terms)
|
||||
public function __construct(GlobalStructure $structure, Thesaurus $thesaurus, CandidateTerms $candidate_terms)
|
||||
{
|
||||
$this->structure = $structure;
|
||||
$this->thesaurus = $thesaurus;
|
||||
@@ -67,7 +68,13 @@ class ThesaurusHydrator implements HydratorInterface
|
||||
$terms = array();
|
||||
$filters = array();
|
||||
$field_names = array();
|
||||
/** @var Field[] $dbFields */
|
||||
$dbFields = $this->structure->getAllFieldsByDatabox($record['databox_id']);
|
||||
foreach ($fields as $name => $field) {
|
||||
if(!array_key_exists($name, $dbFields) || !$dbFields[$name]->get_generate_cterms()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$root_concepts = $field->getThesaurusRoots();
|
||||
// Loop through all values to prepare bulk query
|
||||
$field_values = \igorw\get_in($record, explode('.', $index_fields[$name]));
|
||||
@@ -98,11 +105,8 @@ class ThesaurusHydrator implements HydratorInterface
|
||||
}
|
||||
}
|
||||
else {
|
||||
$field = $fields[$name];
|
||||
if($field->get_generate_cterms()) {
|
||||
$this->candidate_terms->insert($field_names[$offset], $values[$offset]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,11 @@ class Field implements Typed
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $databox_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -73,6 +78,7 @@ class Field implements Typed
|
||||
}
|
||||
|
||||
return new self($field->get_name(), $type, [
|
||||
'databox_id' => $databox->get_sbas_id(),
|
||||
'searchable' => $field->is_indexable(),
|
||||
'private' => $field->isBusiness(),
|
||||
'facet' => $facet,
|
||||
@@ -102,6 +108,7 @@ class Field implements Typed
|
||||
{
|
||||
$this->name = (string) $name;
|
||||
$this->type = $type;
|
||||
$this->databox_id = \igorw\get_in($options, ['databox_id'], 0);
|
||||
$this->is_searchable = \igorw\get_in($options, ['searchable'], true);
|
||||
$this->is_private = \igorw\get_in($options, ['private'], false);
|
||||
$this->facet = \igorw\get_in($options, ['facet']);
|
||||
@@ -126,6 +133,7 @@ class Field implements Typed
|
||||
public function withOptions(array $options)
|
||||
{
|
||||
return new self($this->name, $this->type, $options + [
|
||||
'databox_id' => $this->databox_id,
|
||||
'searchable' => $this->is_searchable,
|
||||
'private' => $this->is_private,
|
||||
'facet' => $this->facet,
|
||||
@@ -155,6 +163,11 @@ class Field implements Typed
|
||||
return sprintf('concept_path.%s', $this->name);
|
||||
}
|
||||
|
||||
public function get_databox_id()
|
||||
{
|
||||
return $this->databox_id;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
|
@@ -14,6 +14,12 @@ final class GlobalStructure implements Structure
|
||||
*/
|
||||
private $fields = array();
|
||||
|
||||
|
||||
/**
|
||||
* @var Field[][]
|
||||
*/
|
||||
private $fieldsByDatabox = [];
|
||||
|
||||
/**
|
||||
* @var Field[]
|
||||
* */
|
||||
@@ -119,6 +125,10 @@ final class GlobalStructure implements Structure
|
||||
|
||||
public function add(Field $field)
|
||||
{
|
||||
// store info for each field, not still merged by databox
|
||||
$this->fieldsByDatabox[$field->get_databox_id()][$field->getName()] = $field;
|
||||
|
||||
// store merged infos (same field name)
|
||||
$name = $field->getName();
|
||||
|
||||
if (isset($this->fields[$name])) {
|
||||
@@ -152,6 +162,11 @@ final class GlobalStructure implements Structure
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
public function getAllFieldsByDatabox($databox_id)
|
||||
{
|
||||
return $this->fieldsByDatabox[$databox_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Field[]
|
||||
*/
|
||||
|
Reference in New Issue
Block a user