public static function escapeTerm($term)
{
$result = $term;
// \ escaping has to be first, otherwise escaped later once again
$chars = ['\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/', '<', '>'];
foreach ($chars as $char) {
$result = str_replace($char, '\\' . $char, $result);
}
return $result;
}