mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 12:33:26 +00:00
Merge pull request #1478 from mdarse/fix-concept-query-builder
Fix concept query builder & private field wrapping
This commit is contained in:
@@ -37,6 +37,9 @@ abstract class AbstractTermNode extends Node implements TermInterface
|
|||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$index_fields[] = $field->getConceptPathIndexField();
|
$index_fields[] = $field->getConceptPathIndexField();
|
||||||
}
|
}
|
||||||
|
if (!$index_fields) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
$query = null;
|
$query = null;
|
||||||
foreach ($concepts as $concept) {
|
foreach ($concepts as $concept) {
|
||||||
$concept_query = [
|
$concept_query = [
|
||||||
|
@@ -70,7 +70,7 @@ class TextNode extends AbstractTermNode implements ContextAbleInterface
|
|||||||
|
|
||||||
$concept_query = $this->buildConceptQuery($context);
|
$concept_query = $this->buildConceptQuery($context);
|
||||||
if ($concept_query !== null) {
|
if ($concept_query !== null) {
|
||||||
$query = QueryHelper::applyBooleanClause($query, 'should', $this->buildConceptQuery($context));
|
$query = QueryHelper::applyBooleanClause($query, 'should', $concept_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
|
@@ -50,8 +50,8 @@ class QueryHelper
|
|||||||
private static function restrictQueryToCollections(array $query, array $collections)
|
private static function restrictQueryToCollections(array $query, array $collections)
|
||||||
{
|
{
|
||||||
$wrapper = [];
|
$wrapper = [];
|
||||||
$wrapper['bool']['must'][0]['terms']['base_id'] = $collections;
|
$wrapper['filtered']['filter']['terms']['base_id'] = $collections;
|
||||||
$wrapper['bool']['must'][1] = $query;
|
$wrapper['filtered']['query'] = $query;
|
||||||
return $wrapper;
|
return $wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +86,7 @@ class QueryHelper
|
|||||||
// Right to query on a private field is dependant of document collection
|
// Right to query on a private field is dependant of document collection
|
||||||
// Here we make sure we can only match on allowed collections
|
// Here we make sure we can only match on allowed collections
|
||||||
$query = $query_builder($fields);
|
$query = $query_builder($fields);
|
||||||
$collection_query = [];
|
$query = self::restrictQueryToCollections($query, $collections_map[$hash]);
|
||||||
$collection_query['terms']['base_id'] = $collections_map[$hash];
|
|
||||||
$query = self::applyBooleanClause($query, 'must', $collection_query);
|
|
||||||
$queries[] = $query;
|
$queries[] = $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -79,19 +79,20 @@ class QuotedTextNodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
"lenient": true
|
"lenient": true
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"bool": {
|
"filtered": {
|
||||||
"must": [{
|
"filter": {
|
||||||
"terms": {
|
"terms": {
|
||||||
"base_id": [1, 2, 3]
|
"base_id": [1, 2, 3]
|
||||||
}
|
}
|
||||||
}, {
|
},
|
||||||
|
"query": {
|
||||||
"multi_match": {
|
"multi_match": {
|
||||||
"type": "phrase",
|
"type": "phrase",
|
||||||
"fields": ["private_caption.bar.fr", "private_caption.bar.en"],
|
"fields": ["private_caption.bar.fr", "private_caption.bar.en"],
|
||||||
"query": "baz",
|
"query": "baz",
|
||||||
"lenient": true
|
"lenient": true
|
||||||
}
|
}
|
||||||
}]
|
}
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@@ -121,23 +121,27 @@ class TermNodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
"query": "/qux"
|
"query": "/qux"
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"bool": {
|
"filtered": {
|
||||||
"must": [{
|
"filter": {
|
||||||
"terms": {
|
"terms": {
|
||||||
"base_id": [1, 2, 3]
|
"base_id": [1, 2, 3]
|
||||||
}
|
}
|
||||||
}],
|
},
|
||||||
"should": [{
|
"query": {
|
||||||
"multi_match": {
|
"bool": {
|
||||||
"fields": ["concept_path.bar"],
|
"should": [{
|
||||||
"query": "/baz"
|
"multi_match": {
|
||||||
|
"fields": ["concept_path.bar"],
|
||||||
|
"query": "/baz"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"multi_match": {
|
||||||
|
"fields": ["concept_path.bar"],
|
||||||
|
"query": "/qux"
|
||||||
|
}
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
}, {
|
}
|
||||||
"multi_match": {
|
|
||||||
"fields": ["concept_path.bar"],
|
|
||||||
"query": "/qux"
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@@ -98,19 +98,20 @@ class TextNodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
"lenient": true
|
"lenient": true
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"bool": {
|
"filtered": {
|
||||||
"must": [{
|
"filter": {
|
||||||
"terms": {
|
"terms": {
|
||||||
"base_id": [1, 2, 3]
|
"base_id": [1, 2, 3]
|
||||||
}
|
}
|
||||||
}, {
|
},
|
||||||
|
"query": {
|
||||||
"multi_match": {
|
"multi_match": {
|
||||||
"fields": ["private_caption.bar.fr", "private_caption.bar.en"],
|
"fields": ["private_caption.bar.fr", "private_caption.bar.en"],
|
||||||
"query": "baz",
|
"query": "baz",
|
||||||
"operator": "and",
|
"operator": "and",
|
||||||
"lenient": true
|
"lenient": true
|
||||||
}
|
}
|
||||||
}]
|
}
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user