I want to search special characters in index.
I escaped all the special characters in query string but when i perform query as + on lucene in index it create query as +().
Hence it search on no fields.
How to solve this problem? My index contains these special characters.
Maybe it's not actual for the author but to be able to search special characters you need:
Example how it works for me:
If you are using the
StandardAnalyzer
, that will discard non-alphanum characters. Try indexing the same value with aWhitespaceAnalyzer
and see if that preserves the characters you need. It might also keep stuff you don't want: that's when you might consider writing your own Analyzer, which basically means creating a TokenStream stack that does exactly the kind of processing you need.For example, the
SimpleAnalyzer
implements the following pipeline:which just lower-cases the tokens.
The
StandardAnalyzer
does much more:You can mix & match from these and other components in
org.apache.lucene.analysis
, or you can write your own specializedTokenStream
instances that are wrapped into a processing pipeline by your customAnalyzer
.One other thing to look at is what sort of
CharTokenizer
you're using.CharTokenizer
is an abstract class that specifies the machinery for tokenizing text strings. It's used by some simpler Analyzers (but not by theStandardAnalyzer
). Lucene comes with two subclasses: aLetterTokenizer
and aWhitespaceTokenizer
. You can create your own that keeps the characters you need and breaks on those you don't by implementing theboolean isTokenChar(char c)
method.