mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Merge pull request #1452 from mdarse/fix-number-field-search
Fix number field search
This commit is contained in:
@@ -23,9 +23,11 @@ class QuotedTextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testQueryBuild()
|
||||
{
|
||||
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$query_context->getLocalizedFields()->willReturn(['foo.fr', 'foo.en']);
|
||||
$query_context->getUnrestrictedFields()->willReturn([$field]);
|
||||
$query_context->getPrivateFields()->willReturn([]);
|
||||
$query_context->localizeField($field)->willReturn(['foo.fr', 'foo.en']);
|
||||
|
||||
$node = new QuotedTextNode('bar');
|
||||
$query = $node->buildQuery($query_context->reveal());
|
||||
@@ -50,11 +52,14 @@ class QuotedTextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
]);
|
||||
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$query_context
|
||||
->getUnrestrictedFields()
|
||||
->willReturn([$public_field]);
|
||||
$query_context
|
||||
->getPrivateFields()
|
||||
->willReturn([$private_field]);
|
||||
$query_context
|
||||
->getLocalizedFields()
|
||||
->localizeField($public_field)
|
||||
->willReturn(['foo.fr', 'foo.en']);
|
||||
$query_context
|
||||
->localizeField($private_field)
|
||||
|
@@ -20,4 +20,53 @@ class RawNodeTest extends \PHPUnit_Framework_TestCase
|
||||
$node = new RawNode('foo');
|
||||
$this->assertEquals('<raw:"foo">', (string) $node);
|
||||
}
|
||||
|
||||
public function testQueryBuildOnSingleField()
|
||||
{
|
||||
$field = $this->prophesize(Field::class);
|
||||
$field->getIndexField(true)->willReturn('foo.raw');
|
||||
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$query_context->getUnrestrictedFields()->willReturn([$field->reveal()]);
|
||||
$query_context->getPrivateFields()->willReturn([]);
|
||||
|
||||
$node = new RawNode('bar');
|
||||
$query = $node->buildQuery($query_context->reveal());
|
||||
|
||||
$expected = '{
|
||||
"term": {
|
||||
"foo.raw": "bar"
|
||||
}
|
||||
}';
|
||||
|
||||
$this->assertEquals(json_decode($expected, true), $query);
|
||||
}
|
||||
|
||||
public function testQueryBuildOnMultipleFields()
|
||||
{
|
||||
$field_a = $this->prophesize(Field::class);
|
||||
$field_a->getIndexField(true)->willReturn('foo.raw');
|
||||
$field_b = $this->prophesize(Field::class);
|
||||
$field_b->getIndexField(true)->willReturn('bar.raw');
|
||||
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$query_context->getUnrestrictedFields()->willReturn([
|
||||
$field_a->reveal(),
|
||||
$field_b->reveal()
|
||||
]);
|
||||
$query_context->getPrivateFields()->willReturn([]);
|
||||
|
||||
$node = new RawNode('baz');
|
||||
$query = $node->buildQuery($query_context->reveal());
|
||||
|
||||
$expected = '{
|
||||
"multi_match": {
|
||||
"query": "baz",
|
||||
"fields": ["foo.raw", "bar.raw"],
|
||||
"analyzer": "keyword"
|
||||
}
|
||||
}';
|
||||
|
||||
$this->assertEquals(json_decode($expected, true), $query);
|
||||
}
|
||||
}
|
||||
|
@@ -35,9 +35,6 @@ class TermNodeTest extends \PHPUnit_Framework_TestCase
|
||||
$query_context
|
||||
->getPrivateFields()
|
||||
->willReturn([]);
|
||||
$query_context
|
||||
->getLocalizedFields()
|
||||
->willReturn(['foo.fr', 'foo.en']);
|
||||
|
||||
$node = new TermNode('bar');
|
||||
$node->setConcepts([
|
||||
@@ -65,6 +62,29 @@ class TermNodeTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(json_decode($expected, true), $query);
|
||||
}
|
||||
|
||||
public function testQueryBuildWithZeroConcept()
|
||||
{
|
||||
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$query_context
|
||||
->getUnrestrictedFields()
|
||||
->willReturn([$field]);
|
||||
$query_context
|
||||
->getPrivateFields()
|
||||
->willReturn([]);
|
||||
|
||||
$node = new TermNode('bar');
|
||||
$query = $node->buildQuery($query_context->reveal());
|
||||
|
||||
$expected = '{
|
||||
"bool": {
|
||||
"should": []
|
||||
}
|
||||
}';
|
||||
|
||||
$this->assertEquals(json_decode($expected, true), $query);
|
||||
}
|
||||
|
||||
public function testQueryBuildWithPrivateFields()
|
||||
{
|
||||
$public_field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
|
||||
|
@@ -42,9 +42,11 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testQueryBuild()
|
||||
{
|
||||
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$query_context->getLocalizedFields()->willReturn(['foo.fr', 'foo.en']);
|
||||
$query_context->getUnrestrictedFields()->willReturn([$field]);
|
||||
$query_context->getPrivateFields()->willReturn([]);
|
||||
$query_context->localizeField($field)->willReturn(['foo.fr', 'foo.en']);
|
||||
|
||||
$node = new TextNode('bar', new Context('baz'));
|
||||
$query = $node->buildQuery($query_context->reveal());
|
||||
@@ -70,7 +72,10 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$query_context
|
||||
->getLocalizedFields()
|
||||
->getUnrestrictedFields()
|
||||
->willReturn([$public_field]);
|
||||
$query_context
|
||||
->localizeField($public_field)
|
||||
->willReturn(['foo.fr', 'foo.en']);
|
||||
$query_context
|
||||
->getPrivateFields()
|
||||
@@ -115,15 +120,9 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$field = new Field('foo', Mapping::TYPE_STRING, ['private' => false]);
|
||||
$query_context = $this->prophesize(QueryContext::class);
|
||||
$query_context
|
||||
->getUnrestrictedFields()
|
||||
->willReturn([$field]);
|
||||
$query_context
|
||||
->getPrivateFields()
|
||||
->willReturn([]);
|
||||
$query_context
|
||||
->getLocalizedFields()
|
||||
->willReturn(['foo.fr', 'foo.en']);
|
||||
$query_context->getUnrestrictedFields()->willReturn([$field]);
|
||||
$query_context->getPrivateFields()->willReturn([]);
|
||||
$query_context->localizeField($field)->willReturn(['foo.fr', 'foo.en']);
|
||||
|
||||
$node = new TextNode('bar');
|
||||
$node->setConcepts([
|
||||
|
Reference in New Issue
Block a user