mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
buildConceptQueriesForFields() replaces buildConceptQueries()
This commit is contained in:
@@ -35,32 +35,7 @@ abstract class AbstractTermNode extends Node implements TermInterface
|
|||||||
return $this->pruned_concepts;
|
return $this->pruned_concepts;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildConceptQueries(QueryContext $context)
|
protected function buildConceptQueries(array $fields)
|
||||||
{
|
|
||||||
if (!$this->getPrunedConcepts()) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$query_builder = function (array $fields) {
|
|
||||||
$concept_queries = $this->buildConceptQueriesForFields($fields);
|
|
||||||
$query = null;
|
|
||||||
foreach ($concept_queries as $concept_query) {
|
|
||||||
$query = QueryHelper::applyBooleanClause($query, 'should', $concept_query);
|
|
||||||
}
|
|
||||||
return $query;
|
|
||||||
};
|
|
||||||
|
|
||||||
$queries = $this->buildConceptQueriesForFields($context->getUnrestrictedFields());
|
|
||||||
|
|
||||||
$private_fields = $context->getPrivateFields();
|
|
||||||
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $query_builder) as $private_field_query) {
|
|
||||||
$queries[] = $private_field_query;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $queries;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildConceptQueriesForFields(array $fields)
|
|
||||||
{
|
{
|
||||||
$concepts = $this->getPrunedConcepts();
|
$concepts = $this->getPrunedConcepts();
|
||||||
if (!$concepts) {
|
if (!$concepts) {
|
||||||
|
|||||||
@@ -3,19 +3,29 @@
|
|||||||
namespace Alchemy\Phrasea\SearchEngine\Elastic\AST;
|
namespace Alchemy\Phrasea\SearchEngine\Elastic\AST;
|
||||||
|
|
||||||
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
||||||
|
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryHelper;
|
||||||
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\Term;
|
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\Term;
|
||||||
|
|
||||||
class TermNode extends AbstractTermNode
|
class TermNode extends AbstractTermNode
|
||||||
{
|
{
|
||||||
public function buildQuery(QueryContext $context)
|
public function buildQuery(QueryContext $context)
|
||||||
{
|
{
|
||||||
// Should not match anything if no concept is defined
|
$query_builder = function (array $fields) {
|
||||||
// TODO Ensure no match when no concept queries are provided
|
$concept_queries = $this->buildConceptQueries($fields);
|
||||||
return [
|
$query = null;
|
||||||
'bool' => [
|
foreach ($concept_queries as $concept_query) {
|
||||||
'should' => $this->buildConceptQueries($context)
|
$query = QueryHelper::applyBooleanClause($query, 'should', $concept_query);
|
||||||
]
|
}
|
||||||
];
|
return $query;
|
||||||
|
};
|
||||||
|
|
||||||
|
$query = $query_builder($context->getUnrestrictedFields());
|
||||||
|
$private_fields = $context->getPrivateFields();
|
||||||
|
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $query_builder) as $concept_query) {
|
||||||
|
$query = QueryHelper::applyBooleanClause($query, 'should', $concept_query);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class TextNode extends AbstractTermNode implements ContextAbleInterface
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
// Thesaurus
|
// Thesaurus
|
||||||
$concept_queries = $this->buildConceptQueriesForFields($fields);
|
$concept_queries = $this->buildConceptQueries($fields);
|
||||||
foreach ($concept_queries as $concept_query) {
|
foreach ($concept_queries as $concept_query) {
|
||||||
$query = QueryHelper::applyBooleanClause($query, 'should', $concept_query);
|
$query = QueryHelper::applyBooleanClause($query, 'should', $concept_query);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,13 +76,7 @@ class TermNodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$node = new TermNode('bar');
|
$node = new TermNode('bar');
|
||||||
$query = $node->buildQuery($query_context->reveal());
|
$query = $node->buildQuery($query_context->reveal());
|
||||||
|
|
||||||
$expected = '{
|
$this->assertNull($query);
|
||||||
"bool": {
|
|
||||||
"should": []
|
|
||||||
}
|
|
||||||
}';
|
|
||||||
|
|
||||||
$this->assertEquals(json_decode($expected, true), $query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryBuildWithPrivateFields()
|
public function testQueryBuildWithPrivateFields()
|
||||||
|
|||||||
Reference in New Issue
Block a user