0
votes

How do I get search hits when at least one character searched is present in a field's value, using lucene search?

I got search hits only when I search with a complete word.

Example: Hello world

In above example, if I enter "Hello", then I will get a hit, but not if I enter "Hel"

Here is my code to get hits:

QueryParser parser = null;
Query query = null;
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT, new HashSet());
BooleanQuery.setMaxClauseCount(32767);
parser = new QueryParser("fieldname", analyzer);
parser.setAllowLeadingWildcard(true);
query = parser.parse("searchString");
TopDocs topResultDocs = searcher.search(query, null, 20);
1

1 Answers

2
votes

Always append * to the query to get all suffix matches: Hel* will match Hello.