Fix number field search

Search with non numeric content will not hit number field (it breaks elasticsearch and is useless anyway)

- Rename QueryHelper::buildPrivateFieldQueries() to wrapPrivateFieldQuery().
    - Signature changed too, the third parameter is dropped an QueryContext is replaced by an array of Field.
    - Query builder closure is now passed an array of Field, not of index field names.
- Remove Field::toConceptPathIndexFieldArray() because method name was beyond understanding (and also because it wasn't needed anymore)
- Various AST node types have changed due to previous API changes
This commit is contained in:
Mathieu Darse
2015-07-23 17:39:11 +02:00
parent daea7f8c77
commit a31442368b
12 changed files with 160 additions and 107 deletions

View File

@@ -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)

View File

@@ -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]);

View File

@@ -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([