I am using Lucene version 5.0.0. In my search string, there is a minus character like “test-”. I read that the minus sign is a special character in Lucene. So I have to escape that sign, as in the queryparser documentation:
Escaping Special Characters: 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
To do that I use the QueryParser.escape
method:
query = parser.parse(QueryParser.escape(searchString));
I use the classic Analyzer because I noticed that the standard Analyzer has some problems with escaping special characters.
The problem is that the Parser deletes the special characters and so the Query has the term content:test
How can I set up the parser and searcher to search for the real value “test-“? I also created my own query with the content test- but that also didn’t work. I recieved 0 results but my index has entries like:
- Test-VRF
- Test-IPLS
I am really confused about this problem.