1

I am saving the following title to index

doc.add(new TextField(TITLE, "Button",Field.Store.YES ));

Then when I search for it with say "butto", nothing returns. I must search for "button" to get anything back. What do I have to do so that any substring of button gives a result? I am using

 StandardAnalyzer analyzer = new StandardAnalyzer();
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199

1 Answers1

4

The StandardAnalyzer creates just the token button for the input text and so, only a query for button matches the document. To search for any substring of button, you have two options.

At search-time, you can use a different query, e.g. a PrefixQuery or a WildcardQuery. If you use the query parser, you can use butto? or butto*.

At index-time, you can use a different analyzer, that emits substrings as tokens, for example the EdgeNGramTokenizer which would emit [bu, but, butt, butto, button] based on the configuration; or the NGramTokenizer, which would emit [bu, ut, tt, to, on] and so on for the configured size(s).

knutwalker
  • 5,924
  • 2
  • 22
  • 29