Merge pull request #1502 from mdarse/ar-731-status-search-dsl

PHRAS-731 Add status match DSL
This commit is contained in:
Nicolas Maillat
2015-09-15 09:22:17 +02:00
6 changed files with 146 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace Alchemy\Tests\Phrasea\SearchEngine\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\FlagStatement;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
/**
* @group unit
* @group searchengine
* @group ast
*/
class FlagStatementTest extends \PHPUnit_Framework_TestCase
{
public function testSerialization()
{
$this->assertTrue(method_exists(FlagStatement::class, '__toString'), 'Class does not have method __toString');
$node = new FlagStatement('foo', true);
$this->assertEquals('<flag:foo set>', (string) $node);
$node = new FlagStatement('foo', false);
$this->assertEquals('<flag:foo cleared>', (string) $node);
}
public function testQueryBuild()
{
$query_context = $this->prophesize(QueryContext::class);
$node = new FlagStatement('foo', true);
$query = $node->buildQuery($query_context->reveal());
$expected = '{
"term": {
"flags.foo": true
}
}';
$this->assertEquals(json_decode($expected, true), $query);
}
}

View File

@@ -78,6 +78,15 @@ id:90 AND foo|(<record_identifier:90> AND <text:"foo">)
id:90 foo|<text:"id:90 foo">
recordid:90|<record_identifier:90>
# Flag matcher
flag.foo:true|<flag:foo set>
flag.foo:1|<flag:foo set>
flag.foo:false|<flag:foo cleared>
flag.foo:0|<flag:foo cleared>
flag.true:true|<flag:true set>
flag.foo bar:true|<text:"flag.foo bar:true">
true|<text:"true">
# Matcher on unknown name --> fulltext
foo:bar|<text:"foo:bar">
Can't render this file because it contains an unexpected character in line 1 and column 11.