I'm using QueryParser::parse()
method to get a query from a string search term for my ZendSearch Lucene index. But I've a problem with the following query:
+php +5.7.1)
This throws the QueryParserException
with message:
Syntax Error: mismatched parentheses, every opening must have closing.
So I used QueryParser::escape()
to escape the string search term before I pass it to QueryParser::parse()
but then it escapes everything so this leads to this string:
\\+\\p\\h\\p\\ \\+\\5\\.\\7\\.\\1\\)
Now the QueryParserException
has gone but also the possbility of using special chars like +
, -
, etc.
I look for a way to just escape special chars which will lead to a QueryParserException
so in my case the )
should be escaped because there is no opening bracket )
in the query but my two +
should stay untouched.
Is there any possbility to achieve this? Building the query itself without parsing is not an option because the search terms are user inputs.
I tried to use QueryParser::suppressQueryParsingExceptions()
which probably would be the thing I'm looking for but it has no effect. The QueryParser
still throws a QueryParserException
although the default value for this is true
.