Wednesday, October 08, 2008

how to escape lucenes search characters

Lucene: Escaping Special Characters |
Thankfully, the necessary code to fix this isn't all that difficult. There are two scenarios at this point: 1.) You are using Lucene 1.9 or newer., or 2.) You are using Lucene 1.4 or prior

If you are using Lucene 1.9, the task of escaping user input for the query parser is very straightforward:

Lucene 1.9 Escaping

String userQuery = // ...
String escaped = QueryParser.escape(userQuery);
Query query = QueryParser.parse(escaped);
// ...

No comments: