Update class for mapping type constants

This commit is contained in:
Thibaud Fabre
2016-10-19 10:12:55 +02:00
parent 6e88b97c55
commit 299b24d4fb
19 changed files with 162 additions and 146 deletions

View File

@@ -30,7 +30,7 @@ class TimestampKey implements Key, Typed
public function getType()
{
return Mapping::TYPE_DATE;
return FieldMapping::TYPE_DATE;
}
public function getIndexField(QueryContext $context, $raw = false)

View File

@@ -332,7 +332,7 @@ class ElasticSearchEngine implements SearchEngineInterface
$highlighted_fields = [];
foreach ($context->getHighlightedFields() as $field) {
switch ($field->getType()) {
case Mapping::TYPE_STRING:
case FieldMapping::TYPE_STRING:
$index_field = $field->getIndexField();
$raw_index_field = $field->getIndexField(true);
$highlighted_fields[$index_field] = [
@@ -341,14 +341,14 @@ class ElasticSearchEngine implements SearchEngineInterface
'type' => 'fvh'
];
break;
case Mapping::TYPE_FLOAT:
case Mapping::TYPE_DOUBLE:
case Mapping::TYPE_INTEGER:
case Mapping::TYPE_LONG:
case Mapping::TYPE_SHORT:
case Mapping::TYPE_BYTE:
case FieldMapping::TYPE_FLOAT:
case FieldMapping::TYPE_DOUBLE:
case FieldMapping::TYPE_INTEGER:
case FieldMapping::TYPE_LONG:
case FieldMapping::TYPE_SHORT:
case FieldMapping::TYPE_BYTE:
continue;
case Mapping::TYPE_DATE:
case FieldMapping::TYPE_DATE:
default:
continue;
}
@@ -488,10 +488,10 @@ class ElasticSearchEngine implements SearchEngineInterface
if ($options->getDateFields() && ($options->getMaxDate() || $options->getMinDate())) {
$range = [];
if ($options->getMaxDate()) {
$range['lte'] = $options->getMaxDate()->format(Mapping::DATE_FORMAT_CAPTION_PHP);
$range['lte'] = $options->getMaxDate()->format(FieldMapping::DATE_FORMAT_CAPTION_PHP);
}
if ($options->getMinDate()) {
$range['gte'] = $options->getMinDate()->format(Mapping::DATE_FORMAT_CAPTION_PHP);
$range['gte'] = $options->getMinDate()->format(FieldMapping::DATE_FORMAT_CAPTION_PHP);
}
foreach ($options->getDateFields() as $dateField) {

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic\Indexer\Record\Hydrator;
use Alchemy\Phrasea\SearchEngine\Elastic\Exception\Exception;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure;
@@ -120,20 +121,20 @@ SQL;
private function sanitizeValue($value, $type)
{
switch ($type) {
case Mapping::TYPE_DATE:
case FieldMapping::TYPE_DATE:
return $this->helper->sanitizeDate($value);
case Mapping::TYPE_FLOAT:
case Mapping::TYPE_DOUBLE:
case FieldMapping::TYPE_FLOAT:
case FieldMapping::TYPE_DOUBLE:
return (float) $value;
case Mapping::TYPE_INTEGER:
case Mapping::TYPE_LONG:
case Mapping::TYPE_SHORT:
case Mapping::TYPE_BYTE:
case FieldMapping::TYPE_INTEGER:
case FieldMapping::TYPE_LONG:
case FieldMapping::TYPE_SHORT:
case FieldMapping::TYPE_BYTE:
return (int) $value;
case Mapping::TYPE_BOOLEAN:
case FieldMapping::TYPE_BOOLEAN:
return (bool) $value;
default:

View File

@@ -95,9 +95,9 @@ class RecordHelper
*/
public static function validateDate($date)
{
$d = DateTime::createFromFormat(Mapping::DATE_FORMAT_CAPTION_PHP, $date);
$d = DateTime::createFromFormat(FieldMapping::DATE_FORMAT_CAPTION_PHP, $date);
return $d && $d->format(Mapping::DATE_FORMAT_CAPTION_PHP) == $date;
return $d && $d->format(FieldMapping::DATE_FORMAT_CAPTION_PHP) == $date;
}
/**
@@ -111,7 +111,7 @@ class RecordHelper
try {
$date = new \DateTime($value);
return $date->format(Mapping::DATE_FORMAT_CAPTION_PHP);
return $date->format(FieldMapping::DATE_FORMAT_CAPTION_PHP);
} catch (\Exception $e) {
return null;
}

View File

@@ -3,6 +3,7 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
use Alchemy\Phrasea\SearchEngine\Elastic\Exception\QueryException;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Field as ASTField;
@@ -101,7 +102,7 @@ class QueryContext
{
$index_field = $field->getIndexField();
if ($field->getType() === Mapping::TYPE_STRING) {
if ($field->getType() === FieldMapping::TYPE_STRING) {
return $this->localizeFieldName($index_field);
} else {
return [$index_field];

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
@@ -142,8 +143,8 @@ class QueryHelper
}
return [
'from' => $from->format(Mapping::DATE_FORMAT_CAPTION_PHP),
'to' => $to->format(Mapping::DATE_FORMAT_CAPTION_PHP)
'from' => $from->format(FieldMapping::DATE_FORMAT_CAPTION_PHP),
'to' => $to->format(FieldMapping::DATE_FORMAT_CAPTION_PHP)
];
}
}

View File

@@ -4,6 +4,7 @@ namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
use Alchemy\Phrasea\SearchEngine\Elastic\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\Exception\Exception;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure;
use Hoa\Compiler\Llk\TreeNode;
@@ -210,7 +211,7 @@ class QueryVisitor implements Visit
if ($key instanceof AST\KeyValue\TimestampKey) {
return true;
} elseif ($key instanceof AST\KeyValue\FieldKey) {
return $this->structure->typeOf($key->getName()) === Mapping::TYPE_DATE;
return $this->structure->typeOf($key->getName()) === FieldMapping::TYPE_DATE;
}
return false;
}

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;
@@ -41,7 +42,7 @@ class Tag implements Typed
return sprintf(
'metadata_tags.%s%s',
$this->name,
$raw && $this->type === Mapping::TYPE_STRING ? '.raw' : ''
$raw && $this->type === FieldMapping::TYPE_STRING ? '.raw' : ''
);
}
}

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 Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper;
use Assert\Assertion;
@@ -23,22 +24,22 @@ class ValueChecker
$filtered = [];
foreach ($list as $item) {
switch ($item->getType()) {
case Mapping::TYPE_FLOAT:
case Mapping::TYPE_DOUBLE:
case Mapping::TYPE_INTEGER:
case Mapping::TYPE_LONG:
case Mapping::TYPE_SHORT:
case Mapping::TYPE_BYTE:
case FieldMapping::TYPE_FLOAT:
case FieldMapping::TYPE_DOUBLE:
case FieldMapping::TYPE_INTEGER:
case FieldMapping::TYPE_LONG:
case FieldMapping::TYPE_SHORT:
case FieldMapping::TYPE_BYTE:
if ($is_numeric) {
$filtered[] = $item;
}
break;
case Mapping::TYPE_DATE:
case FieldMapping::TYPE_DATE:
if ($is_valid_date) {
$filtered[] = $item;
}
break;
case Mapping::TYPE_STRING:
case FieldMapping::TYPE_STRING:
default:
$filtered[] = $item;
}

View File

@@ -3,6 +3,7 @@
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\QuotedTextNode;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
@@ -23,7 +24,7 @@ class QuotedTextNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuild()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$query_context = $this->prophesize(QueryContext::class);
$query_context->getUnrestrictedFields()->willReturn([$field]);
$query_context->getPrivateFields()->willReturn([]);
@@ -46,8 +47,8 @@ class QuotedTextNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuildWithPrivateFields()
{
$public_field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$private_field = new Field('bar', Mapping::TYPE_STRING, [
$public_field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$private_field = new Field('bar', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 2, 3]
]);

View File

@@ -3,6 +3,7 @@
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\RawNode;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
@@ -24,7 +25,7 @@ class RawNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuildOnSingleField()
{
$field = $this->prophesize(Field::class);
$field->getType()->willReturn(Mapping::TYPE_STRING);
$field->getType()->willReturn(FieldMapping::TYPE_STRING);
$field->getIndexField(true)->willReturn('foo.raw');
$query_context = $this->prophesize(QueryContext::class);
@@ -46,10 +47,10 @@ class RawNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuildOnMultipleFields()
{
$field_a = $this->prophesize(Field::class);
$field_a->getType()->willReturn(Mapping::TYPE_STRING);
$field_a->getType()->willReturn(FieldMapping::TYPE_STRING);
$field_a->getIndexField(true)->willReturn('foo.raw');
$field_b = $this->prophesize(Field::class);
$field_b->getType()->willReturn(Mapping::TYPE_STRING);
$field_b->getType()->willReturn(FieldMapping::TYPE_STRING);
$field_b->getIndexField(true)->willReturn('bar.raw');
$query_context = $this->prophesize(QueryContext::class);

View File

@@ -4,6 +4,7 @@ namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Context;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\TermNode;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
@@ -27,7 +28,7 @@ class TermNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuild()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$query_context = $this->prophesize(QueryContext::class);
$query_context
->getUnrestrictedFields()
@@ -64,7 +65,7 @@ class TermNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuildWithZeroConcept()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$query_context = $this->prophesize(QueryContext::class);
$query_context
->getUnrestrictedFields()
@@ -81,8 +82,8 @@ class TermNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuildWithPrivateFields()
{
$public_field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$private_field = new Field('bar', Mapping::TYPE_STRING, [
$public_field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$private_field = new Field('bar', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 2, 3]
]);

View File

@@ -4,6 +4,7 @@ namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Context;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\TextNode;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
@@ -42,7 +43,7 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuild()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$query_context = $this->prophesize(QueryContext::class);
$query_context->getUnrestrictedFields()->willReturn([$field]);
$query_context->getPrivateFields()->willReturn([]);
@@ -66,8 +67,8 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuildWithPrivateFields()
{
$public_field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$private_field = new Field('bar', Mapping::TYPE_STRING, [
$public_field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$private_field = new Field('bar', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 2, 3]
]);
@@ -125,7 +126,7 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuildWithConcepts()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$query_context = $this->prophesize(QueryContext::class);
$query_context->getUnrestrictedFields()->willReturn([$field]);
$query_context->getPrivateFields()->willReturn([]);
@@ -161,8 +162,8 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
public function testQueryBuildWithPrivateFieldAndConcept()
{
$public_field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$private_field = new Field('bar', Mapping::TYPE_STRING, [
$public_field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$private_field = new Field('bar', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 2, 3]
]);

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Tests\Phrasea\SearchEngine\Search;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\AggregationHelper;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
@@ -14,7 +15,7 @@ class AggregationHelperTest extends \PHPUnit_Framework_TestCase
{
public function testAggregationWrappingOnPrivateField()
{
$field = new Field('foo', Mapping::TYPE_STRING, [
$field = new Field('foo', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 2, 3]
]);
@@ -40,7 +41,7 @@ class AggregationHelperTest extends \PHPUnit_Framework_TestCase
public function testAggregationWrappingOnUnrestrictedField()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$agg = [
'terms' => 'bar'
];

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Tests\Phrasea\SearchEngine\Search;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
@@ -24,8 +25,8 @@ class QueryContextTest extends \PHPUnit_Framework_TestCase
public function testGetUnrestrictedFields()
{
$foo_field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$bar_field = new Field('bar', Mapping::TYPE_STRING, ['private' => false]);
$foo_field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$bar_field = new Field('bar', FieldMapping::TYPE_STRING, ['private' => false]);
$structure = $this->prophesize(Structure::class);
$structure->getUnrestrictedFields()->willReturn([
'foo' => $foo_field,
@@ -41,8 +42,8 @@ class QueryContextTest extends \PHPUnit_Framework_TestCase
public function testGetPrivateFields()
{
$foo_field = new Field('foo', Mapping::TYPE_STRING, ['private' => true]);
$bar_field = new Field('bar', Mapping::TYPE_STRING, ['private' => true]);
$foo_field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => true]);
$bar_field = new Field('bar', FieldMapping::TYPE_STRING, ['private' => true]);
$structure = $this->prophesize(Structure::class);
$structure->getPrivateFields()->willReturn([
'foo' => $foo_field,

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Tests\Phrasea\SearchEngine\Structure;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\Concept;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
@@ -14,14 +15,14 @@ class FieldTest extends \PHPUnit_Framework_TestCase
{
public function testBasicMerge()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['used_by_collections' => ['1', '2']]);
$other = new Field('foo', Mapping::TYPE_STRING, ['used_by_collections' => ['3', '4']]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['used_by_collections' => ['1', '2']]);
$other = new Field('foo', FieldMapping::TYPE_STRING, ['used_by_collections' => ['3', '4']]);
$merged = $field->mergeWith($other);
$this->assertInstanceOf(Field::class, $merged);
$this->assertNotSame($field, $merged);
$this->assertNotSame($other, $merged);
$this->assertEquals('foo', $merged->getName());
$this->assertEquals(Mapping::TYPE_STRING, $merged->getType());
$this->assertEquals(FieldMapping::TYPE_STRING, $merged->getType());
$this->assertTrue($merged->isSearchable());
$this->assertFalse($merged->isPrivate());
$this->assertFalse($merged->isFacet());
@@ -35,8 +36,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase
*/
public function testConflictingNameMerge()
{
$field = new Field('foo', Mapping::TYPE_STRING);
$other = new Field('bar', Mapping::TYPE_STRING);
$field = new Field('foo', FieldMapping::TYPE_STRING);
$other = new Field('bar', FieldMapping::TYPE_STRING);
$field->mergeWith($other);
}
@@ -46,8 +47,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase
*/
public function testConflictingTypeMerge()
{
$field = new Field('foo', Mapping::TYPE_STRING);
$other = new Field('foo', Mapping::TYPE_DATE);
$field = new Field('foo', FieldMapping::TYPE_STRING);
$other = new Field('foo', FieldMapping::TYPE_DATE);
$field->mergeWith($other);
}
@@ -57,8 +58,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase
*/
public function testMixedSearchabilityMerge()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['searchable' => true]);
$other = new Field('foo', Mapping::TYPE_STRING, ['searchable' => false]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['searchable' => true]);
$other = new Field('foo', FieldMapping::TYPE_STRING, ['searchable' => false]);
$field->mergeWith($other);
}
@@ -68,8 +69,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase
*/
public function testMixedPrivateAndPublicMerge()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => true]);
$other = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => true]);
$other = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$field->mergeWith($other);
}
@@ -79,8 +80,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase
*/
public function testMixedFacetEligibilityMerge()
{
$field = new Field('foo', Mapping::TYPE_STRING, ['facet' => Field::FACET_NO_LIMIT]);
$other = new Field('foo', Mapping::TYPE_STRING, ['facet' => Field::FACET_DISABLED]);
$field = new Field('foo', FieldMapping::TYPE_STRING, ['facet' => Field::FACET_NO_LIMIT]);
$other = new Field('foo', FieldMapping::TYPE_STRING, ['facet' => Field::FACET_DISABLED]);
$field->mergeWith($other);
}
@@ -88,8 +89,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase
{
$foo = new Concept('/foo');
$bar = new Concept('/bar');
$field = new Field('foo', Mapping::TYPE_STRING);
$other = new Field('foo', Mapping::TYPE_STRING, [
$field = new Field('foo', FieldMapping::TYPE_STRING);
$other = new Field('foo', FieldMapping::TYPE_STRING, [
'thesaurus_roots' => [$foo, $bar]
]);
$merged = $field->mergeWith($other);
@@ -97,10 +98,10 @@ class FieldTest extends \PHPUnit_Framework_TestCase
$foo = new Concept('/foo');
$bar = new Concept('/bar');
$field = new Field('foo', Mapping::TYPE_STRING, [
$field = new Field('foo', FieldMapping::TYPE_STRING, [
'thesaurus_roots' => [$foo]
]);
$other = new Field('foo', Mapping::TYPE_STRING, [
$other = new Field('foo', FieldMapping::TYPE_STRING, [
'thesaurus_roots' => [$bar]
]);
$merged = $field->mergeWith($other);
@@ -109,10 +110,10 @@ class FieldTest extends \PHPUnit_Framework_TestCase
public function testMergeWithDependantCollections()
{
$field = new Field('foo', Mapping::TYPE_STRING, [
$field = new Field('foo', FieldMapping::TYPE_STRING, [
'used_by_collections' => [1, 2]
]);
$other = new Field('foo', Mapping::TYPE_STRING, [
$other = new Field('foo', FieldMapping::TYPE_STRING, [
'used_by_collections' => [2, 3]
]);
$merged = $field->mergeWith($other);

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Tests\Phrasea\SearchEngine\Structure;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\LimitedStructure;
@@ -16,7 +17,7 @@ class LimitedStructureTest extends \PHPUnit_Framework_TestCase
{
public function testGetUnrestrictedFields()
{
$field = new Field('foo', Mapping::TYPE_STRING);
$field = new Field('foo', FieldMapping::TYPE_STRING);
$wrapped = $this->prophesize(Structure::class);
$wrapped
->getUnrestrictedFields()
@@ -38,13 +39,13 @@ class LimitedStructureTest extends \PHPUnit_Framework_TestCase
$wrapped->get('foo')
->shouldBeCalled()
->willReturn(
new Field('foo', Mapping::TYPE_STRING, [
new Field('foo', FieldMapping::TYPE_STRING, [
'used_by_collections' => [1, 2, 3]
])
)
;
$this->assertEquals(
new Field('foo', Mapping::TYPE_STRING, [
new Field('foo', FieldMapping::TYPE_STRING, [
'used_by_collections' => [2]
]),
$structure->get('foo')
@@ -65,21 +66,21 @@ class LimitedStructureTest extends \PHPUnit_Framework_TestCase
$structure = new LimitedStructure($wrapped->reveal(), $options->reveal());
$wrapped->getAllFields()->willReturn([
'foo' => new Field('foo', Mapping::TYPE_STRING, [
'foo' => new Field('foo', FieldMapping::TYPE_STRING, [
'private' => false,
'used_by_collections' => [1, 2, 3]
]),
'bar' => new Field('bar', Mapping::TYPE_STRING, [
'bar' => new Field('bar', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 2, 3]
])
]);
$this->assertEquals([
'foo' => new Field('foo', Mapping::TYPE_STRING, [
'foo' => new Field('foo', FieldMapping::TYPE_STRING, [
'private' => false,
'used_by_collections' => [1, 2, 3]
]),
'bar' => new Field('bar', Mapping::TYPE_STRING, [
'bar' => new Field('bar', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 3]
])

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Tests\Phrasea\SearchEngine\Structure;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\Concept;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
@@ -30,7 +31,7 @@ class StructureTest extends \PHPUnit_Framework_TestCase
$field = $this->prophesize(Field::class);
$field->getName()->willReturn('foo');
$field->getType()->willReturn(Mapping::TYPE_STRING);
$field->getType()->willReturn(FieldMapping::TYPE_STRING);
$field->isPrivate()->willReturn(false);
$field->isFacet()->willReturn(false);
$field->hasConceptInference()->willReturn(false);
@@ -39,9 +40,9 @@ class StructureTest extends \PHPUnit_Framework_TestCase
$structure->add($field->reveal());
$this->assertCount(1, $structure->getAllFields());
$conflicting_field = new Field('foo', Mapping::TYPE_STRING, ['2']);
$conflicting_field = new Field('foo', FieldMapping::TYPE_STRING, ['2']);
$merged = new Field('foo', Mapping::TYPE_STRING, ['1', '2']);
$merged = new Field('foo', FieldMapping::TYPE_STRING, ['1', '2']);
$field->mergeWith($conflicting_field)->willReturn($merged);
// Should still have only one (both have the same name)
@@ -55,14 +56,14 @@ class StructureTest extends \PHPUnit_Framework_TestCase
{
$field = $this->prophesize(Field::class);
$field->getName()->willReturn('foo');
$field->getType()->willReturn(Mapping::TYPE_STRING);
$field->getType()->willReturn(FieldMapping::TYPE_STRING);
$field->isPrivate()->willReturn(false);
$field->isFacet()->willReturn(false);
$field->hasConceptInference()->willReturn(false);
$other = new Field('foo', Mapping::TYPE_STRING);
$other = new Field('foo', FieldMapping::TYPE_STRING);
$merged = new Field('foo', Mapping::TYPE_STRING);
$merged = new Field('foo', FieldMapping::TYPE_STRING);
$field->mergeWith($other)->shouldBeCalled()->willReturn($merged);
$structure = new Structure();
@@ -74,9 +75,9 @@ class StructureTest extends \PHPUnit_Framework_TestCase
public function testFieldsRestrictions()
{
$structure = new Structure();
$unrestricted_field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
$unrestricted_field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
$structure->add($unrestricted_field);
$private_field = new Field('bar', Mapping::TYPE_STRING, ['private' => true]);
$private_field = new Field('bar', FieldMapping::TYPE_STRING, ['private' => true]);
$structure->add($private_field);
// All
$all_fields = $structure->getAllFields();
@@ -94,8 +95,8 @@ class StructureTest extends \PHPUnit_Framework_TestCase
public function testGetFacetFields()
{
$facet = new Field('foo', Mapping::TYPE_STRING, ['facet' => Field::FACET_NO_LIMIT]);
$not_facet = new Field('bar', Mapping::TYPE_STRING, ['facet' => Field::FACET_DISABLED]);
$facet = new Field('foo', FieldMapping::TYPE_STRING, ['facet' => Field::FACET_NO_LIMIT]);
$not_facet = new Field('bar', FieldMapping::TYPE_STRING, ['facet' => Field::FACET_DISABLED]);
$structure = new Structure();
$structure->add($facet);
$this->assertContains($facet, $structure->getFacetFields());
@@ -107,8 +108,8 @@ class StructureTest extends \PHPUnit_Framework_TestCase
public function testGetDateFields()
{
$string = new Field('foo', Mapping::TYPE_STRING);
$date = new Field('bar', Mapping::TYPE_DATE);
$string = new Field('foo', FieldMapping::TYPE_STRING);
$date = new Field('bar', FieldMapping::TYPE_DATE);
$structure = new Structure();
$structure->add($string);
$this->assertNotContains($string, $structure->getDateFields());
@@ -120,10 +121,10 @@ class StructureTest extends \PHPUnit_Framework_TestCase
public function testGetThesaurusEnabledFields()
{
$not_enabled = new Field('foo', Mapping::TYPE_STRING, [
$not_enabled = new Field('foo', FieldMapping::TYPE_STRING, [
'thesaurus_roots' => null
]);
$enabled = new Field('bar', Mapping::TYPE_STRING, [
$enabled = new Field('bar', FieldMapping::TYPE_STRING, [
'thesaurus_roots' => [new Concept('/foo')]
]);
$structure = new Structure();
@@ -138,7 +139,7 @@ class StructureTest extends \PHPUnit_Framework_TestCase
public function testGet()
{
$structure = new Structure();
$field = new Field('foo', Mapping::TYPE_STRING);
$field = new Field('foo', FieldMapping::TYPE_STRING);
$structure->add($field);
$this->assertEquals($field, $structure->get('foo'));
$this->assertNull($structure->get('bar'));
@@ -147,19 +148,19 @@ class StructureTest extends \PHPUnit_Framework_TestCase
public function testTypeCheck()
{
$structure = new Structure();
$structure->add(new Field('foo', Mapping::TYPE_STRING));
$structure->add(new Field('bar', Mapping::TYPE_DATE));
$structure->add(new Field('baz', Mapping::TYPE_DOUBLE));
$this->assertEquals(Mapping::TYPE_STRING, $structure->typeOf('foo'));
$this->assertEquals(Mapping::TYPE_DATE, $structure->typeOf('bar'));
$this->assertEquals(Mapping::TYPE_DOUBLE, $structure->typeOf('baz'));
$structure->add(new Field('foo', FieldMapping::TYPE_STRING));
$structure->add(new Field('bar', FieldMapping::TYPE_DATE));
$structure->add(new Field('baz', FieldMapping::TYPE_DOUBLE));
$this->assertEquals(FieldMapping::TYPE_STRING, $structure->typeOf('foo'));
$this->assertEquals(FieldMapping::TYPE_DATE, $structure->typeOf('bar'));
$this->assertEquals(FieldMapping::TYPE_DOUBLE, $structure->typeOf('baz'));
}
public function testPrivateCheck()
{
$structure = new Structure();
$structure->add(new Field('foo', Mapping::TYPE_STRING, ['private' => false]));
$structure->add(new Field('bar', Mapping::TYPE_STRING, ['private' => true]));
$structure->add(new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]));
$structure->add(new Field('bar', FieldMapping::TYPE_STRING, ['private' => true]));
$this->assertFalse($structure->isPrivate('foo'));
$this->assertTrue($structure->isPrivate('bar'));
}
@@ -177,19 +178,19 @@ class StructureTest extends \PHPUnit_Framework_TestCase
public function testCollectionsUsedByPrivateFields()
{
$structure = new Structure();
$structure->add($foo = (new Field('foo', Mapping::TYPE_STRING, [
$structure->add($foo = (new Field('foo', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 2]
])));
$structure->add(new Field('foo', Mapping::TYPE_STRING, [
$structure->add(new Field('foo', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [2, 3]
]));
$structure->add(new Field('bar', Mapping::TYPE_STRING, [
$structure->add(new Field('bar', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [2, 3]
]));
$structure->add(new Field('baz', Mapping::TYPE_STRING, ['private' => false]));
$structure->add(new Field('baz', FieldMapping::TYPE_STRING, ['private' => false]));
$this->assertEquals([1, 2], $foo->getDependantCollections());
static $expected = [
'foo' => [1, 2, 3],

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Tests\Phrasea\SearchEngine\Structure;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\ValueChecker;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Typed;
@@ -23,45 +24,45 @@ class ValueCheckerTest extends \PHPUnit_Framework_TestCase
public function escapeRawProvider()
{
$values = [
[Mapping::TYPE_FLOAT , 42 , true ],
[Mapping::TYPE_FLOAT , '42' , true ],
[Mapping::TYPE_FLOAT , '42foo' , false],
[Mapping::TYPE_FLOAT , 'foo' , false],
[Mapping::TYPE_DOUBLE , 42 , true ],
[Mapping::TYPE_DOUBLE , '42' , true ],
[Mapping::TYPE_DOUBLE , '42foo' , false],
[Mapping::TYPE_DOUBLE , 'foo' , false],
[Mapping::TYPE_INTEGER, 42 , true ],
[Mapping::TYPE_INTEGER, '42' , true ],
[Mapping::TYPE_INTEGER, '42foo' , false],
[Mapping::TYPE_INTEGER, 'foo' , false],
[Mapping::TYPE_LONG , 42 , true ],
[Mapping::TYPE_LONG , '42' , true ],
[Mapping::TYPE_LONG , '42foo' , false],
[Mapping::TYPE_LONG , 'foo' , false],
[Mapping::TYPE_SHORT , 42 , true ],
[Mapping::TYPE_SHORT , '42' , true ],
[Mapping::TYPE_SHORT , '42foo' , false],
[Mapping::TYPE_SHORT , 'foo' , false],
[Mapping::TYPE_BYTE , 42 , true ],
[Mapping::TYPE_BYTE , '42' , true ],
[Mapping::TYPE_BYTE , '42foo' , false],
[Mapping::TYPE_BYTE , 'foo' , false],
[FieldMapping::TYPE_FLOAT , 42 , true ],
[FieldMapping::TYPE_FLOAT , '42' , true ],
[FieldMapping::TYPE_FLOAT , '42foo' , false],
[FieldMapping::TYPE_FLOAT , 'foo' , false],
[FieldMapping::TYPE_DOUBLE , 42 , true ],
[FieldMapping::TYPE_DOUBLE , '42' , true ],
[FieldMapping::TYPE_DOUBLE , '42foo' , false],
[FieldMapping::TYPE_DOUBLE , 'foo' , false],
[FieldMapping::TYPE_INTEGER, 42 , true ],
[FieldMapping::TYPE_INTEGER, '42' , true ],
[FieldMapping::TYPE_INTEGER, '42foo' , false],
[FieldMapping::TYPE_INTEGER, 'foo' , false],
[FieldMapping::TYPE_LONG , 42 , true ],
[FieldMapping::TYPE_LONG , '42' , true ],
[FieldMapping::TYPE_LONG , '42foo' , false],
[FieldMapping::TYPE_LONG , 'foo' , false],
[FieldMapping::TYPE_SHORT , 42 , true ],
[FieldMapping::TYPE_SHORT , '42' , true ],
[FieldMapping::TYPE_SHORT , '42foo' , false],
[FieldMapping::TYPE_SHORT , 'foo' , false],
[FieldMapping::TYPE_BYTE , 42 , true ],
[FieldMapping::TYPE_BYTE , '42' , true ],
[FieldMapping::TYPE_BYTE , '42foo' , false],
[FieldMapping::TYPE_BYTE , 'foo' , false],
[Mapping::TYPE_STRING , 'foo' , true ],
[Mapping::TYPE_STRING , '42' , true ],
[Mapping::TYPE_STRING , 42 , true ],
[FieldMapping::TYPE_STRING , 'foo' , true ],
[FieldMapping::TYPE_STRING , '42' , true ],
[FieldMapping::TYPE_STRING , 42 , true ],
[Mapping::TYPE_BOOLEAN, true , true ],
[Mapping::TYPE_BOOLEAN, false , true ],
[Mapping::TYPE_BOOLEAN, 'yes' , true ],
[Mapping::TYPE_BOOLEAN, 'no' , true ],
[Mapping::TYPE_BOOLEAN, 'foo' , true ],
[Mapping::TYPE_BOOLEAN, 42 , true ],
[FieldMapping::TYPE_BOOLEAN, true , true ],
[FieldMapping::TYPE_BOOLEAN, false , true ],
[FieldMapping::TYPE_BOOLEAN, 'yes' , true ],
[FieldMapping::TYPE_BOOLEAN, 'no' , true ],
[FieldMapping::TYPE_BOOLEAN, 'foo' , true ],
[FieldMapping::TYPE_BOOLEAN, 42 , true ],
[Mapping::TYPE_DATE , '2015/01/01' , true ],
[Mapping::TYPE_DATE , '2015/01/01 00:00:00', false],
[Mapping::TYPE_DATE , 'foo' , false],
[FieldMapping::TYPE_DATE , '2015/01/01' , true ],
[FieldMapping::TYPE_DATE , '2015/01/01 00:00:00', false],
[FieldMapping::TYPE_DATE , 'foo' , false],
];
foreach ($values as &$value) {