Implement private fields on range an equal nodes

New QueryContext::get() method
Removed QueryContext::normalizeField(), can be replaced with get() and a call to
Field::getIndexField().
This commit is contained in:
Mathieu Darse
2015-07-16 20:11:43 +02:00
parent 78ab5b31dc
commit 44cb5824e7
5 changed files with 56 additions and 42 deletions

View File

@@ -2,6 +2,8 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
class QueryHelper
{
private function __construct() {}
@@ -28,15 +30,32 @@ class QueryHelper
foreach ($fields_map as $hash => $fields) {
// Right to query on a private field is dependant of document collection
// Here we make sure we can only match on allowed collections
$query = [];
$query['bool']['must'][0]['terms']['base_id'] = $collections_map[$hash];
$query['bool']['must'][1] = $matcher_callback->__invoke($fields);
$queries[] = $query;
$queries[] = self::restrictQueryToCollections(
$matcher_callback->__invoke($fields),
$collections_map[$hash]
);
}
return $queries;
}
public static function wrapPrivateFieldQuery(Field $field, array $query)
{
if ($field->isPrivate()) {
return self::restrictQueryToCollections($query, $field->getDependantCollections());
} else {
return $query;
}
}
private static function restrictQueryToCollections(array $query, array $collections)
{
$wrapper = [];
$wrapper['bool']['must'][0]['terms']['base_id'] = $collections;
$wrapper['bool']['must'][1] = $query;
return $wrapper;
}
private static function hashCollections(array $collections)
{
sort($collections, SORT_REGULAR);