I have implemented RamDirectory with StandandAnalyzer, and am storing places data in Lucene cache, I have added data in Lucene like below :
final Document document = new Document();
final IndexableField id = new StringField("placeId", place.getPlaceId(), Field.Store.YES);
final IndexableField name = new TextField("name", place.getName().toLowerCase(), Field.Store.YES);
final IndexableField location = new LatLonPoint("location", place.getLatitude(), place.getLongitude());
final IndexableField city = new StringField("city", place.getCity(), Field.Store.YES);
document.add(id);
document.add(name);
document.add(location);
document.add(city);
I've implemented two approaches to search the data, One is nearby places in defined radius, which works well, and another is to search places by name. And we have to implement autocomplete feature on search by name as well.
I've implemented search by name as follows:
QueryParser parser = new QueryParser("name", analyzer);
return parser.createPhraseQuery("name", searchStr, 2);
Now I have a place with name Lets say "Tom clinic and pharmacy".
If I search using following phrases I get the result back:
- Tom
- Tom clinic
- Tom pharmacy
Which is great, but if a user types "Tom clini" or "Tom pharma", Lucene gives me no results back.
I have tried to add a "*" at the end of the searchStr, tried passing the phrase to a wildcardQuery(which works fine on a single word, but fails on multiple words).
Also I would like to add fuzziness a bit so typos can be handled, I'm new to Lucene and not sure what to do from here, so help me out anyhow you can!
P.S Its Lucene 7.3