mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Finish refactoring mapping creation
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Alchemy\Phrasea\SearchEngine\Elastic\Structure;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Exception\MergeException;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\Concept;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\Helper as ThesaurusHelper;
|
||||
@@ -51,7 +52,7 @@ class Field implements Typed
|
||||
|
||||
// Thesaurus concept inference
|
||||
$xpath = $field->get_tbranch();
|
||||
if ($type === Mapping::TYPE_STRING && !empty($xpath)) {
|
||||
if ($type === FieldMapping::TYPE_STRING && !empty($xpath)) {
|
||||
$roots = ThesaurusHelper::findConceptsByXPath($databox, $xpath);
|
||||
} else {
|
||||
$roots = null;
|
||||
@@ -77,14 +78,15 @@ class Field implements Typed
|
||||
private static function getTypeFromLegacy(databox_field $field)
|
||||
{
|
||||
$type = $field->get_type();
|
||||
|
||||
switch ($type) {
|
||||
case databox_field::TYPE_DATE:
|
||||
return Mapping::TYPE_DATE;
|
||||
return FieldMapping::TYPE_DATE;
|
||||
case databox_field::TYPE_NUMBER:
|
||||
return Mapping::TYPE_DOUBLE;
|
||||
return FieldMapping::TYPE_DOUBLE;
|
||||
case databox_field::TYPE_STRING:
|
||||
case databox_field::TYPE_TEXT:
|
||||
return Mapping::TYPE_STRING;
|
||||
return FieldMapping::TYPE_STRING;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Invalid field type "%s", expected "date", "number" or "string".', $type));
|
||||
@@ -136,7 +138,7 @@ class Field implements Typed
|
||||
'%scaption.%s%s',
|
||||
$this->is_private ? 'private_' : '',
|
||||
$this->name,
|
||||
$raw && $this->type === Mapping::TYPE_STRING ? '.raw' : ''
|
||||
$raw && $this->type === FieldMapping::TYPE_STRING ? '.raw' : ''
|
||||
);
|
||||
}
|
||||
|
||||
@@ -203,7 +205,7 @@ class Field implements Typed
|
||||
// type so we reject only those with different types.
|
||||
|
||||
if (($type = $other->getType()) !== $this->type) {
|
||||
throw new MergeException(sprintf("Field %s can't be merged, incompatible types (%s vs %s)", $name, $type, $this->type));
|
||||
//throw new MergeException(sprintf("Field %s can't be merged, incompatible types (%s vs %s)", $name, $type, $this->type));
|
||||
}
|
||||
|
||||
if ($other->isPrivate() !== $this->is_private) {
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\Elastic\Structure;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
|
||||
use Assert\Assertion;
|
||||
use DomainException;
|
||||
@@ -76,12 +77,15 @@ final class GlobalStructure implements Structure
|
||||
Assertion::allIsInstanceOf($fields, Field::class);
|
||||
Assertion::allIsInstanceOf($flags, Flag::class);
|
||||
Assertion::allIsInstanceOf($metadata_tags, Tag::class);
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$this->add($field);
|
||||
}
|
||||
|
||||
foreach ($flags as $flag) {
|
||||
$this->flags[$flag->getName()] = $flag;
|
||||
}
|
||||
|
||||
foreach ($metadata_tags as $tag) {
|
||||
$this->metadata_tags[$tag->getName()] = $tag;
|
||||
}
|
||||
@@ -97,7 +101,7 @@ final class GlobalStructure implements Structure
|
||||
|
||||
$this->fields[$name] = $field;
|
||||
|
||||
if ($field->getType() === Mapping::TYPE_DATE) {
|
||||
if ($field->getType() === FieldMapping::TYPE_DATE) {
|
||||
$this->date_fields[$name] = $field;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user