mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Same grammar path for native keys than « IN » expressions
- Replace Database/Collection/Type/RecordIdentifier specific AST with a generic KeyValueExpression - « IN » queries in regular fields are still using InExpression right now - Add some tests for « type:XXXX » queries
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Key;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValueExpression;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
* @group searchengine
|
||||
* @group ast
|
||||
*/
|
||||
class KeyValueExpressionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSerialization()
|
||||
{
|
||||
$this->assertTrue(method_exists(KeyValueExpression::class, '__toString'), 'Class does not have method __toString');
|
||||
$node = new KeyValueExpression(Key::database(), 'bar');
|
||||
$this->assertEquals('<database:bar>', (string) $node);
|
||||
}
|
||||
|
||||
public function testQueryBuild()
|
||||
{
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$key = $this->prophesize(Key::class);
|
||||
$key->getIndexField()->willReturn('foo');
|
||||
|
||||
$node = new KeyValueExpression($key->reveal(), 'bar');
|
||||
$query = $node->buildQuery($query_context->reveal());
|
||||
|
||||
$expected = '{
|
||||
"term": {
|
||||
"foo": "bar"
|
||||
}
|
||||
}';
|
||||
|
||||
$this->assertEquals(json_decode($expected, true), $query);
|
||||
}
|
||||
}
|
@@ -66,6 +66,27 @@ foo bar IN baz|(<text:"foo bar"> IN <field:baz>)
|
||||
foo IN bar baz|<text:"foo IN bar baz">
|
||||
fooINbar|<text:"fooINbar">
|
||||
|
||||
# Native fields with IN syntax (temporary)
|
||||
foo IN collection|<collection:foo>
|
||||
foo IN collection AND bar|(<collection:foo> AND <text:"bar">)
|
||||
foo IN collection bar|<text:"foo IN collection bar">
|
||||
foo IN database|<database:foo>
|
||||
foo IN database AND bar|(<database:foo> AND <text:"bar">)
|
||||
foo IN database bar|<text:"foo IN database bar">
|
||||
foo IN type|<media_type:foo>
|
||||
foo IN type AND bar|(<media_type:foo> AND <text:"bar">)
|
||||
foo IN type bar|<text:"foo IN type bar">
|
||||
90 IN id|<record_identifier:90>
|
||||
90 IN id AND foo|(<record_identifier:90> AND <text:"foo">)
|
||||
90 IN id foo|<text:"90 IN id foo">
|
||||
90 IN recordid|<record_identifier:90>
|
||||
|
||||
# Regular field with name colliding with a native key
|
||||
foo IN field.collection|(<text:"foo"> IN <field:collection>)
|
||||
foo IN field.database|(<text:"foo"> IN <field:database>)
|
||||
foo IN field.type|(<text:"foo"> IN <field:type>)
|
||||
foo IN field.id|(<text:"foo"> IN <field:id>)
|
||||
|
||||
# Matchers
|
||||
collection:foo|<collection:foo>
|
||||
collection:foo AND bar|(<collection:foo> AND <text:"bar">)
|
||||
@@ -73,6 +94,9 @@ collection:foo bar|<text:"collection:foo bar">
|
||||
database:foo|<database:foo>
|
||||
database:foo AND bar|(<database:foo> AND <text:"bar">)
|
||||
database:foo bar|<text:"database:foo bar">
|
||||
type:foo|<media_type:foo>
|
||||
type:foo AND bar|(<media_type:foo> AND <text:"bar">)
|
||||
type:foo bar|<text:"type:foo bar">
|
||||
id:90|<record_identifier:90>
|
||||
id:90 AND foo|(<record_identifier:90> AND <text:"foo">)
|
||||
id:90 foo|<text:"id:90 foo">
|
||||
|
Can't render this file because it contains an unexpected character in line 1 and column 11.
|
Reference in New Issue
Block a user