mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 09:53:15 +00:00
Merge pull request #2988 from aynsix/PHRAS-2497-port-41-search-when-mix-data
PHRAS-2497 Port TO 4.1 - Search issue when query mix data from Public and Private field
This commit is contained in:
@@ -43,7 +43,7 @@ class QuotedTextNode extends Node
|
||||
|
||||
$private_fields = $context->getPrivateFields();
|
||||
$private_fields = ValueChecker::filterByValueCompatibility($private_fields, $this->text);
|
||||
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $query_builder) as $private_field_query) {
|
||||
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $unrestricted_fields, $query_builder) as $private_field_query) {
|
||||
$query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query);
|
||||
}
|
||||
|
||||
|
@@ -61,7 +61,7 @@ class RawNode extends Node
|
||||
|
||||
$private_fields = $context->getPrivateFields();
|
||||
$private_fields = ValueChecker::filterByValueCompatibility($private_fields, $this->text);
|
||||
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $query_builder) as $private_field_query) {
|
||||
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $unrestricted_fields, $query_builder) as $private_field_query) {
|
||||
$query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query);
|
||||
}
|
||||
|
||||
|
@@ -19,9 +19,11 @@ class TermNode extends AbstractTermNode
|
||||
return $query;
|
||||
};
|
||||
|
||||
$query = $query_builder($context->getUnrestrictedFields());
|
||||
$unrestricted_fields = $context->getUnrestrictedFields();
|
||||
$private_fields = $context->getPrivateFields();
|
||||
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $query_builder) as $concept_query) {
|
||||
$query = $query_builder($unrestricted_fields);
|
||||
|
||||
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $unrestricted_fields, $query_builder) as $concept_query) {
|
||||
$query = QueryHelper::applyBooleanClause($query, 'should', $concept_query);
|
||||
}
|
||||
|
||||
|
@@ -66,12 +66,11 @@ class TextNode extends AbstractTermNode implements ContextAbleInterface
|
||||
return $query;
|
||||
};
|
||||
|
||||
// Unrestricted fields
|
||||
$query = $query_builder($context->getUnrestrictedFields());
|
||||
|
||||
// Private fields
|
||||
$unrestricted_fields = $context->getUnrestrictedFields();
|
||||
$private_fields = $context->getPrivateFields();
|
||||
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $query_builder) as $private_field_query) {
|
||||
|
||||
$query = $query_builder($unrestricted_fields);
|
||||
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $unrestricted_fields, $query_builder) as $private_field_query) {
|
||||
$query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query);
|
||||
}
|
||||
|
||||
|
@@ -10,13 +10,13 @@ class QueryHelper
|
||||
{
|
||||
private function __construct() {}
|
||||
|
||||
public static function wrapPrivateFieldQueries(array $fields, \Closure $query_builder)
|
||||
public static function wrapPrivateFieldQueries(array $private_fields, array $unrestricted_fields, \Closure $query_builder)
|
||||
{
|
||||
// We make a boolean clause for each collection set to shrink query size
|
||||
// (instead of a clause for each field, with his collection set)
|
||||
$fields_map = [];
|
||||
$collections_map = [];
|
||||
foreach ($fields as $field) {
|
||||
foreach ($private_fields as $field) {
|
||||
$collections = $field->getDependantCollections();
|
||||
$hash = self::hashCollections($collections);
|
||||
$collections_map[$hash] = $collections;
|
||||
@@ -31,7 +31,7 @@ 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_builder($fields);
|
||||
$query = $query_builder(array_merge($fields, $unrestricted_fields));
|
||||
if ($query !== null) {
|
||||
$queries[] = self::restrictQueryToCollections($query, $collections_map[$hash]);
|
||||
}
|
||||
|
@@ -47,7 +47,9 @@ class QuotedTextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testQueryBuildWithPrivateFields()
|
||||
{
|
||||
$public_field = new Field('foo', FieldMapping::TYPE_STRING, ['private' => false]);
|
||||
$public_field = new Field('foo', FieldMapping::TYPE_STRING, [
|
||||
'private' => false
|
||||
]);
|
||||
$private_field = new Field('bar', FieldMapping::TYPE_STRING, [
|
||||
'private' => true,
|
||||
'used_by_collections' => [1, 2, 3]
|
||||
@@ -75,7 +77,10 @@ class QuotedTextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
"should": [{
|
||||
"multi_match": {
|
||||
"type": "phrase",
|
||||
"fields": ["foo.fr", "foo.en"],
|
||||
"fields": [
|
||||
"foo.fr",
|
||||
"foo.en"
|
||||
],
|
||||
"query": "baz",
|
||||
"lenient": true
|
||||
}
|
||||
@@ -89,7 +94,12 @@ class QuotedTextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
"query": {
|
||||
"multi_match": {
|
||||
"type": "phrase",
|
||||
"fields": ["private_caption.bar.fr", "private_caption.bar.en"],
|
||||
"fields": [
|
||||
"private_caption.bar.fr",
|
||||
"private_caption.bar.en",
|
||||
"foo.fr",
|
||||
"foo.en"
|
||||
],
|
||||
"query": "baz",
|
||||
"lenient": true
|
||||
}
|
||||
|
@@ -126,12 +126,18 @@ class TermNodeTest extends \PHPUnit_Framework_TestCase
|
||||
"bool": {
|
||||
"should": [{
|
||||
"multi_match": {
|
||||
"fields": ["concept_path.bar"],
|
||||
"fields": [
|
||||
"concept_path.bar",
|
||||
"concept_path.foo"
|
||||
],
|
||||
"query": "/baz"
|
||||
}
|
||||
}, {
|
||||
"multi_match": {
|
||||
"fields": ["concept_path.bar"],
|
||||
"fields": [
|
||||
"concept_path.bar",
|
||||
"concept_path.foo"
|
||||
],
|
||||
"query": "/qux"
|
||||
}
|
||||
}]
|
||||
|
@@ -109,7 +109,12 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
},
|
||||
"query": {
|
||||
"multi_match": {
|
||||
"fields": ["private_caption.bar.fr", "private_caption.bar.en"],
|
||||
"fields": [
|
||||
"private_caption.bar.fr",
|
||||
"private_caption.bar.en",
|
||||
"foo.fr",
|
||||
"foo.en"
|
||||
],
|
||||
"query": "baz",
|
||||
"type": "cross_fields",
|
||||
"operator": "and",
|
||||
@@ -216,7 +221,12 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
"bool": {
|
||||
"should": [{
|
||||
"multi_match": {
|
||||
"fields": ["private_caption.bar.fr", "private_caption.bar.en"],
|
||||
"fields": [
|
||||
"private_caption.bar.fr",
|
||||
"private_caption.bar.en",
|
||||
"foo.fr",
|
||||
"foo.en"
|
||||
],
|
||||
"query": "baz",
|
||||
"type": "cross_fields",
|
||||
"operator": "and",
|
||||
@@ -224,7 +234,10 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
}, {
|
||||
"multi_match": {
|
||||
"fields": ["concept_path.bar"],
|
||||
"fields": [
|
||||
"concept_path.bar",
|
||||
"concept_path.foo"
|
||||
],
|
||||
"query": "/qux"
|
||||
}
|
||||
}]
|
||||
|
Reference in New Issue
Block a user