Files
Phraseanet/lib/Alchemy/Phrasea/SearchEngine/Elastic/AST/RawNode.php
Mathieu Darse a31442368b Fix number field search
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
2015-07-23 17:39:11 +02:00

69 lines
1.9 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 as StructureField;
class RawNode extends Node
{
private $text;
private $index_fields_callback;
public static function createFromEscaped($escaped)
{
$unescaped = str_replace(
['\\\\', '\\"'],
['\\', '"'],
$escaped
);
return new self($unescaped);
}
public function __construct($text)
{
$this->text = $text;
}
public function buildQuery(QueryContext $context)
{
$query_builder = function (array $fields) {
$index_fields = [];
foreach ($fields as $field) {
$index_fields[] = $field->getIndexField(true);
}
$query = [];
if (count($index_fields) > 1) {
$query['multi_match']['query'] = $this->text;
$query['multi_match']['fields'] = $index_fields;
$query['multi_match']['analyzer'] = 'keyword';
} else {
$index_field = reset($index_fields);
$query['term'][$index_field] = $this->text;
}
return $query;
};
$query = $query_builder($context->getUnrestrictedFields());
$private_fields = $context->getPrivateFields();
foreach (QueryHelper::wrapPrivateFieldQueries($private_fields, $query_builder) as $private_field_query) {
$query = QueryHelper::applyBooleanClause($query, 'should', $private_field_query);
}
return $query;
}
public function getTermNodes()
{
return [];
}
public function __toString()
{
return sprintf('<raw:"%s">', $this->text);
}
}