Finish refactoring mapping creation

This commit is contained in:
Thibaud Fabre
2016-10-18 20:06:49 +02:00
parent 7a71886dc9
commit f2cfe93f8c
13 changed files with 552 additions and 226 deletions

View File

@@ -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) {

View File

@@ -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;
}