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