mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 06:23:18 +00:00

Clicking on a facet value on the left pane now return the expected result count. This commit implement a new "raw" matcher. It can be used like `r"some raw value"`. It operate on the the `.raw` multi-field and skips all analysis. Escaping `"` is supported by prepending a backslash `\"`. You can also escape the escaping character `\` by doubling it (`\\`). Adds a new `ContextAbleInterface` to differenciate matcher supporting an optional context from those who can't. Fixes an issue with `QueryContext::narrowToFields()` ignoring passed fields.
53 lines
1.1 KiB
PHP
53 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Phrasea\SearchEngine\Elastic\AST;
|
|
|
|
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
|
|
|
class RawNode extends Node
|
|
{
|
|
private $text;
|
|
|
|
public static function createFromEscaped($escaped)
|
|
{
|
|
$unescaped = str_replace(
|
|
array('\\\\', '\\"'),
|
|
array('\\', '"'),
|
|
$escaped
|
|
);
|
|
|
|
return new self($unescaped);
|
|
}
|
|
|
|
public function __construct($text)
|
|
{
|
|
$this->text = $text;
|
|
}
|
|
|
|
public function buildQuery(QueryContext $context)
|
|
{
|
|
$fields = $context->getRawFields();
|
|
$query = array();
|
|
if (count($fields) > 1) {
|
|
$query['multi_match']['query'] = $this->text;
|
|
$query['multi_match']['fields'] = $fields;
|
|
$query['multi_match']['analyzer'] = 'keyword';
|
|
} else {
|
|
$field = reset($fields);
|
|
$query['term'][$field] = $this->text;
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function getTermNodes()
|
|
{
|
|
return array();
|
|
}
|
|
|
|
public function __toString()
|
|
{
|
|
return sprintf('<raw:"%s">', $this->text);
|
|
}
|
|
}
|