mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 13:03:20 +00:00

Search with non numeric content will not hit number field (it breaks elasticsearch and is useless anyway) - Rename QueryHelper::buildPrivateFieldQueries() to wrapPrivateFieldQuery(). - Signature changed too, the third parameter is dropped an QueryContext is replaced by an array of Field. - Query builder closure is now passed an array of Field, not of index field names. - Remove Field::toConceptPathIndexFieldArray() because method name was beyond understanding (and also because it wasn't needed anymore) - Various AST node types have changed due to previous API changes
82 lines
2.3 KiB
PHP
82 lines
2.3 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\Structure\Field;
|
|
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 = [];
|
|
|
|
public function __construct($text, Context $context = null)
|
|
{
|
|
$this->text = $text;
|
|
$this->context = $context;
|
|
}
|
|
|
|
public function setConcepts(array $concepts)
|
|
{
|
|
$this->concepts = $concepts;
|
|
}
|
|
|
|
protected function buildConceptQuery(QueryContext $context)
|
|
{
|
|
$concepts = Concept::pruneNarrowConcepts($this->concepts);
|
|
if (!$concepts) {
|
|
return null;
|
|
}
|
|
|
|
$query_builder = function (array $fields) use ($concepts) {
|
|
$index_fields = [];
|
|
foreach ($fields as $field) {
|
|
$index_fields[] = $field->getConceptPathIndexField();
|
|
}
|
|
$query = null;
|
|
foreach ($concepts as $concept) {
|
|
$concept_query = [
|
|
'multi_match' => [
|
|
'fields' => $index_fields,
|
|
'query' => $concept->getPath()
|
|
]
|
|
];
|
|
$query = QueryHelper::applyBooleanClause($query, 'should', $concept_query);
|
|
}
|
|
return $query;
|
|
};
|
|
|
|
$query = $query_builder($context->getUnrestrictedFields());
|
|
$private_fields = $context->getPrivateFields();
|
|
foreach (QueryHelper::wrapPrivateFieldConceptQueries($private_fields, $query_builder) as $private_field_query) {
|
|
$query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
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];
|
|
}
|
|
}
|