Reputation: 125
i indexed my database to lucene for full text search. everything works fine when searching for keywords which has no symbols but whenever i search for keywords having slashes, decimals, etc. (i.e. 1/4, 1.234, 1-1/4") lucene returns no search results. what is the best way to do in indexing symbols?
Upvotes: 0
Views: 340
Reputation: 1145
Fortunately, newer versions of Lucene already have a convenience method for escaping the said characters in the form of a static method called escape(String s) in QueryParser.
From the docs:
public static String escape(String s)
Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding \.
Upvotes: 1
Reputation: 955
Lucene has a couple of characters that should be escaped:
The characters that need to be escaped are: + - ! ( ) { } [ ] ^ " ~ * ? : \
Upvotes: 3
Reputation: 1979
I'd suggest taking a look at Regular Expression. It should allow you to see if a string contains that character, where it is, and will allow you to replace it.
JavaDocs on Regular Expressions Here
Upvotes: 1