Lucene supports escaping special characters that are part of the query syntax. The current list special characters are
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \
To escape these character use the \ before the character. For example to search for (1+1):2 use the query:
\(1\+1\)\:2
My question is how to escape from whole string at one go? For example myStringToEscape = "ABC^ " ~ * ? :DEF";
How to get a escapedString.
If you are just looking for simple replacement, this will do the trick.
This will output:
You can use
QueryParser.escape
, such as: