diff --git a/lib/Elastica/Util.php b/lib/Elastica/Util.php index 4a0cc2e84e..7be2659763 100644 --- a/lib/Elastica/Util.php +++ b/lib/Elastica/Util.php @@ -44,12 +44,15 @@ public static function escapeTerm($term) { $result = $term; // \ escaping has to be first, otherwise escaped later once again - $chars = array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/'); + $chars = array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':'); foreach ($chars as $char) { $result = str_replace($char, '\\' . $char, $result); } + // since elastisearch uses lucene 4.0 / needs to be escaped by \\ + $result = str_replace('/', '\\\\/', $result); + return $result; } diff --git a/test/lib/Elastica/Test/UtilTest.php b/test/lib/Elastica/Test/UtilTest.php index 381d0c6564..09d4b5b117 100644 --- a/test/lib/Elastica/Test/UtilTest.php +++ b/test/lib/Elastica/Test/UtilTest.php @@ -32,7 +32,7 @@ public function getEscapeTermPairs() public function testEscapeTermSpecialCharacters() { $before = '\\+-&&||!(){}[]^"~*?:/'; - $after = '\\\\\\+\\-\\&&\\||\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?\\:\\/'; + $after = '\\\\\\+\\-\\&&\\||\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?\\:\\\\/'; $this->assertEquals(Util::escapeTerm($before), $after); }