mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Fix search when narrowed to private fields only
This commit is contained in:
@@ -26,7 +26,9 @@ class QuotedTextNode extends Node
|
||||
];
|
||||
};
|
||||
|
||||
$query = $query_builder($context->getLocalizedFields());
|
||||
$fields = $context->getLocalizedFields();
|
||||
$query = $fields ? $query_builder($fields) : null;
|
||||
|
||||
foreach (QueryHelper::buildPrivateFieldQueries($context, $query_builder) as $private_field_query) {
|
||||
$query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query);
|
||||
}
|
||||
|
@@ -41,7 +41,9 @@ class RawNode extends Node
|
||||
return $query;
|
||||
};
|
||||
|
||||
$query = $query_builder($context->getRawFields());
|
||||
$fields = $context->getRawFields();
|
||||
$query = count($fields) ? $query_builder($fields) : null;
|
||||
|
||||
foreach (QueryHelper::buildPrivateFieldQueries($context, $query_builder) as $private_field_query) {
|
||||
$query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query);
|
||||
}
|
||||
|
@@ -47,7 +47,9 @@ class TextNode extends AbstractTermNode implements ContextAbleInterface
|
||||
];
|
||||
};
|
||||
|
||||
$query = $query_builder($context->getLocalizedFields());
|
||||
$fields = $context->getLocalizedFields();
|
||||
$query = count($fields) ? $query_builder($fields) : null;
|
||||
|
||||
foreach (QueryHelper::buildPrivateFieldQueries($context, $query_builder) as $private_field_query) {
|
||||
$query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query);
|
||||
}
|
||||
|
@@ -86,12 +86,20 @@ class QueryHelper
|
||||
* @param array $sub_query Clause query
|
||||
* @return array Resulting query
|
||||
*/
|
||||
public static function applyBooleanClause(array $query, $type, array $clause)
|
||||
public static function applyBooleanClause($query, $type, array $clause)
|
||||
{
|
||||
if (!in_array($type, ['must', 'should'])) {
|
||||
throw new \InvalidArgumentException(sprintf('Type must be either "must" or "should", "%s" given', $type));
|
||||
}
|
||||
|
||||
if ($query === null) {
|
||||
return $clause;
|
||||
}
|
||||
|
||||
if (!is_array($query)) {
|
||||
throw new \InvalidArgumentException(sprintf('Query must be either an array or null, "%s" given', gettype($query)));
|
||||
}
|
||||
|
||||
if (!isset($query['bool'])) {
|
||||
// Wrap in a boolean query
|
||||
$bool = [];
|
||||
|
Reference in New Issue
Block a user