Files
Phraseanet/lib/Alchemy/Phrasea/SearchEngine/Elastic/AST/AbstractTermNode.php
Mathieu Darse e4ec73c58b Same grammar path for native keys than « IN » expressions
- Replace Database/Collection/Type/RecordIdentifier specific AST with a generic KeyValueExpression
- « IN » queries in regular fields are still using InExpression right now
- Add some tests for « type:XXXX » queries
2015-10-06 18:41:51 +02:00

84 lines
2.0 KiB
PHP

<?php
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\Concept;
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\TermInterface;
abstract class AbstractTermNode extends Node implements TermInterface
{
protected $text;
protected $context;
private $concepts = [];
private $pruned_concepts;
public function __construct($text, Context $context = null)
{
$this->text = $text;
$this->context = $context;
}
public function setConcepts(array $concepts)
{
$this->pruned_concepts = null;
$this->concepts = $concepts;
}
private function getPrunedConcepts()
{
if ($this->pruned_concepts === null) {
$this->pruned_concepts = Concept::pruneNarrowConcepts($this->concepts);
}
return $this->pruned_concepts;
}
protected function buildConceptQueries(array $fields)
{
$concepts = $this->getPrunedConcepts();
if (!$concepts) {
return [];
}
$index_fields = [];
foreach ($fields as $field) {
$index_fields[] = $field->getConceptPathIndexField();
}
if (!$index_fields) {
return [];
}
$queries = [];
foreach ($concepts as $concept) {
$queries[] = [
'multi_match' => [
'fields' => $index_fields,
'query' => $concept->getPath()
]
];
}
return $queries;
}
public function getValue()
{
return $this->text;
}
public function hasContext()
{
return $this->context !== null;
}
public function getContext()
{
return $this->context->getValue();
}
public function getTermNodes()
{
return [$this];
}
}