Files
Phraseanet/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/Escaper.php
Mathieu Darse 38465a591f Strict facet matching
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.
2015-04-09 20:32:13 +02:00

25 lines
585 B
PHP

<?php
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
class Escaper
{
public function escapeWord($value)
{
// Strip double quotes from values to prevent broken queries
// TODO escape double quotes when it will be supported in query parser
$value = str_replace('/["\(\)\[\]]+/u', ' ', $value);
if (preg_match('/[\s\(\)\[\]]/u', $value)) {
return sprintf('"%s"', $value);
}
return $value;
}
public function escapeRaw($value)
{
return preg_replace('/"|\\\\/u', '\\\\$0', $value);
}
}