mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
[skip ci] PHRAS-3417_search-empty-fields_MASTER
add : special values "_empty_" and "_any_" to search empty field or not-empty field. Works only with = operator. e.g.: Title=_empty_ wip/todo : unit test ; facet
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Node;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryPostProcessor;
|
||||
|
||||
class MissingExpression extends Node
|
||||
{
|
||||
const MISSING_VALUE = '_empty_';
|
||||
|
||||
private $key;
|
||||
private $value;
|
||||
|
||||
public function __construct(Key $key)
|
||||
{
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
public function buildQuery(QueryContext $context)
|
||||
{
|
||||
$query = [
|
||||
'bool' => [
|
||||
'must_not' => [
|
||||
'exists' => [
|
||||
'field' => $this->key->getIndexField($context, true)
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->key instanceof QueryPostProcessor) {
|
||||
return $this->key->postProcessQuery($query, $context);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getTermNodes()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf('(<%s> == <%s>)', $this->key, self::MISSING_VALUE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user