mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
30 lines
689 B
PHP
30 lines
689 B
PHP
<?php
|
|
|
|
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
|
|
|
|
class Escaper
|
|
{
|
|
public function quoteWord($value)
|
|
{
|
|
return '"' . $this->escapeRaw($value) . '"';
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|