【发布时间】:2018-09-25 07:42:27
【问题描述】:
我已经用 StandandAnalyzer 实现了 RamDirectory,并将数据存储在 Lucene 缓存中,我在 Lucene 中添加了如下数据:
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);
我实现了两种搜索数据的方法,一种是定义半径内的附近地点,效果很好,另一种是按名称搜索地点。 我们还必须在按名称搜索时实现自动完成功能。
我已经实现了按名称搜索如下:
QueryParser parser = new QueryParser("name", analyzer);
return parser.createPhraseQuery("name", searchStr, 2);
现在我有了一个名字,可以说“汤姆诊所和药房”。
如果我使用以下短语进行搜索,我会返回结果:
- 汤姆
- 汤姆诊所
- 汤姆药房
这很好,但如果用户键入“Tom clini”或“Tom pharma”,Lucene 不会返回任何结果。
我尝试在 searchStr 的末尾添加一个“*”,尝试将短语传递给通配符查询(它在单个单词上工作正常,但在多个单词上失败)。
另外我想添加一些模糊性,以便可以处理错别字,我是 Lucene 的新手,不知道从这里做什么,所以尽你所能帮助我!
P.S 它的 Lucene 7.3
【问题讨论】:
-
你用的是什么分析仪?
-
标准分析仪
-
你用例来做前缀搜索吗?或者例如,如果您只是搜索药房,您还想匹配具有“汤姆诊所和药房”的文档吗?