Files
Phraseanet/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/Query.php
Mathieu Darse afbb0e3696 Handle queries with invalid fields
They lead to zero result instead of all results from elasticsearch.
2015-07-23 19:11:12 +02:00

42 lines
826 B
PHP

<?php
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Node;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\NullQueryNode;
use Hoa\Compiler\Llk\TreeNode;
class Query
{
private $root;
public function __construct(Node $root = null)
{
if (!$root) {
$root = new NullQueryNode();
}
$this->root = $root;
}
public function getTermNodes()
{
return $this->root->getTermNodes();
}
public function build(QueryContext $context)
{
$query = $this->root->buildQuery($context);
if ($query === null) {
$query = [];
$query['bool']['must'] = [];
}
return $query;
}
public function dump()
{
return $this->root->__toString();
}
}