maccramers
maccramers

Reputation: 125

searching for keywords with symbols in lucene

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

Answers (3)

pm_labs
pm_labs

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

RobinUS2
RobinUS2

Reputation: 955

Lucene has a couple of characters that should be escaped:

The characters that need to be escaped are: + - ! ( ) { } [ ] ^ " ~ * ? : \

Upvotes: 3

Bry6n
Bry6n

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

Related Questions