Files
Phraseanet/lib/Alchemy/Phrasea/SearchEngine/Elastic/AST/FieldEqualsExpression.php
Mathieu Darse 77b9faaa4e Handle equality test on metadata
Still need some work on testing side
2015-11-06 19:34:09 +01:00

52 lines
1.3 KiB
PHP

<?php
namespace Alchemy\Phrasea\SearchEngine\Elastic\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue\FieldKey;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue\Key;
use Alchemy\Phrasea\SearchEngine\Elastic\Exception\QueryException;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryHelper;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryPostProcessor;
class FieldEqualsExpression extends Node
{
private $key;
private $value;
public function __construct(Key $key, $value)
{
$this->key = $key;
$this->value = $value;
}
public function buildQuery(QueryContext $context)
{
if (!$this->key->isValueCompatible($this->value, $context)) {
return null;
}
$query = [
'term' => [
$this->key->getIndexField($context, true) => $this->value
]
];
if ($this->key instanceof QueryPostProcessor) {
return $this->key->postProcessQuery($query, $context);
}
return $query;
}
public function getTermNodes()
{
return array();
}
public function __toString()
{
return sprintf('(<%s> == <value:"%s">)', $this->key, $this->value);
}
}