mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Fix facets on non string fields & fix raw with "in" query
This commit is contained in:
@@ -34,12 +34,12 @@ class RawNode extends Node
|
||||
foreach ($fields as $field) {
|
||||
$index_fields[] = $field->getIndexField(true);
|
||||
}
|
||||
$query = [];
|
||||
$query = null;
|
||||
if (count($index_fields) > 1) {
|
||||
$query['multi_match']['query'] = $this->text;
|
||||
$query['multi_match']['fields'] = $index_fields;
|
||||
$query['multi_match']['analyzer'] = 'keyword';
|
||||
} else {
|
||||
} elseif (count($index_fields) === 1) {
|
||||
$index_field = reset($index_fields);
|
||||
$query['term'][$index_field] = $this->text;
|
||||
}
|
||||
|
@@ -101,7 +101,7 @@ class Field
|
||||
'%scaption.%s%s',
|
||||
$this->is_private ? 'private_' : '',
|
||||
$this->name,
|
||||
$raw ? '.raw' : ''
|
||||
$raw && $this->type === Mapping::TYPE_STRING ? '.raw' : ''
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user