Handle equality test on metadata

Still need some work on testing side
This commit is contained in:
Mathieu Darse
2015-11-06 19:34:09 +01:00
parent 3d7ab6a292
commit 77b9faaa4e
5 changed files with 48 additions and 47 deletions

View File

@@ -2,8 +2,8 @@
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Field as ASTField;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\FieldEqualsExpression;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue\Key;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field as StructureField;
@@ -17,10 +17,10 @@ class FieldEqualsExpressionTest extends \PHPUnit_Framework_TestCase
public function testSerialization()
{
$this->assertTrue(method_exists(FieldEqualsExpression::class, '__toString'), 'Class does not have method __toString');
$field = $this->prophesize(ASTField::class);
$field->__toString()->willReturn('foo');
$node = new FieldEqualsExpression($field->reveal(), 'bar');
$this->assertEquals('(foo == <value:"bar">)', (string) $node);
$key = $this->prophesize(Key::class);
$key->__toString()->willReturn('foo');
$node = new FieldEqualsExpression($key->reveal(), 'bar');
$this->assertEquals('(<foo> == <value:"bar">)', (string) $node);
}
/**
@@ -28,20 +28,15 @@ class FieldEqualsExpressionTest extends \PHPUnit_Framework_TestCase
*/
public function testQueryBuild($index_field, $value, $compatible_value, $private, $expected_json)
{
$structure_field = $this->prophesize(StructureField::class);
$structure_field->isValueCompatible($value)->willReturn($compatible_value);
$structure_field->getIndexField(true)->willReturn($index_field);
$structure_field->isPrivate()->willReturn($private);
if ($private) {
$structure_field->getDependantCollections()->willReturn(['baz', 'qux']);
}
$query_context = $this->prophesize(QueryContext::class)->reveal();
$ast_field = $this->prophesize(ASTField::class);
$query_context = $this->prophesize(QueryContext::class);
$query_context->get($ast_field->reveal())->willReturn($structure_field);
$key = $this->prophesize(Key::class);
$key->isValueCompatible($value, $query_context)->willReturn($compatible_value);
$key->getIndexField($query_context, true)->willReturn($index_field);
// TODO Test keys implementing QueryPostProcessor
$node = new FieldEqualsExpression($ast_field->reveal(), 'bar');
$query = $node->buildQuery($query_context->reveal());
$node = new FieldEqualsExpression($key->reveal(), 'bar');
$query = $node->buildQuery($query_context);
$this->assertEquals(json_decode($expected_json, true), $query);
}
@@ -49,14 +44,15 @@ class FieldEqualsExpressionTest extends \PHPUnit_Framework_TestCase
public function queryProvider()
{
return [
['foo.raw', 'bar', true, true, '{
"filtered": {
"filter": {
"terms": {
"base_id": ["baz","qux"] } },
"query": {
"term": {
"foo.raw": "bar" } } } }'],
// TODO Put this case in another test case
// ['foo.raw', 'bar', true, true, '{
// "filtered": {
// "filter": {
// "terms": {
// "base_id": ["baz","qux"] } },
// "query": {
// "term": {
// "foo.raw": "bar" } } } }'],
['foo.raw', 'bar', true, false, '{
"term": {
"foo.raw": "bar" } }'],

View File

@@ -61,9 +61,9 @@ foo < "2015/01/01"|<range:field.foo lt="2015/01/01">
foo ≤ "2015/01/01"|<range:field.foo lte="2015/01/01">
foo > "2015/01/01"|<range:field.foo gt="2015/01/01">
foo ≥ "2015/01/01"|<range:field.foo gte="2015/01/01">
foo = 42|(<field:foo> == <value:"42">)
foo = bar|(<field:foo> == <value:"bar">)
foo = "bar"|(<field:foo> == <value:"bar">)
foo = 42|(<field.foo> == <value:"42">)
foo = bar|(<field.foo> == <value:"bar">)
foo = "bar"|(<field.foo> == <value:"bar">)
# Field narrowing
foo:bar|(<field:foo> MATCHES <text:"bar">)
@@ -109,6 +109,7 @@ meta.Duration < 300|<range:metadata.Duration lt="300">
meta.Duration ≤ 300|<range:metadata.Duration lte="300">
meta.Duration > 300|<range:metadata.Duration gt="300">
meta.Duration ≥ 300|<range:metadata.Duration gte="300">
meta.Duration = 300|(<metadata.Duration> == <value:"300">)
# Unescaped "." issue on key prefixes
fieldOne:foo|(<field:fieldOne> MATCHES <text:"foo">)
Can't render this file because it contains an unexpected character in line 1 and column 11.