File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -1368,9 +1368,15 @@ public function halfEscapeMatch($string)
13681368 $ string .= '" ' ;
13691369 }
13701370
1371+ $ string = preg_replace ('/-[\s-]*-/u ' , '- ' , $ string );
1372+
13711373 $ from_to_preg = array (
1372- "' \"([^\s]+)-([^\s]*) \"' " => "\\1\- \\2 " ,
1373- "'([^\s]+)-([^\s]*)' " => "\"\\1\- \\2 \""
1374+ '/([-|])\s*$/u ' => '\\\\\1 ' ,
1375+ '/\|[\s|]*\|/u ' => '| ' ,
1376+
1377+ // prevent accidental negation in natural language
1378+ '/(\S+)-(\S+)/u ' => '\1\-\2 ' ,
1379+ '/(\S+)\s+-\s+(\S+)/u ' => '\1 \- \2 ' ,
13741380 );
13751381
13761382 $ string = mb_strtolower (preg_replace (array_keys ($ from_to_preg ), array_values ($ from_to_preg ), $ string ));
Original file line number Diff line number Diff line change @@ -393,6 +393,7 @@ public function testEscapeMatch()
393393 public function testHalfEscapeMatch ()
394394 {
395395 $ this ->assertSame ('this maybe that\^32 and | hi ' , SphinxQL::create ($ this ->conn )->halfEscapeMatch ('this MAYBE that^32 and | hi ' ));
396+ $ this ->assertSame ('this \- not -that | hi \- ' , SphinxQL::create ($ this ->conn )->halfEscapeMatch ('this -- not -that | | hi - ' ));
396397 $ this ->assertSame ('stärkergradig | mb ' , SphinxQL::create ($ this ->conn )->halfEscapeMatch ('stärkergradig | mb ' ));
397398 }
398399
You can’t perform that action at this time.
0 commit comments