小编Ibr*_*aiq的帖子

带有不完整单词的Lucene Phrase查询

我已经使用 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);
Run Code Online (Sandbox Code Playgroud)

我已经实现了两种搜索数据的方法,一种是定义半径内的附近地点,效果很好,另一种是按名称搜索地点。我们还必须在按名称搜索时实现自动完成功能。

我已经按名称实现了搜索,如下所示:

QueryParser parser = new QueryParser("name", analyzer);
return parser.createPhraseQuery("name", searchStr, 2);
Run Code Online (Sandbox Code Playgroud)

现在我有一个名字叫“汤姆诊所和药房”的地方。

如果我使用以下短语进行搜索,则会返回结果:

  1. 汤姆
  2. 汤姆诊所
  3. 汤姆药房

这很好,但是如果用户输入“Tom clini”或“Tom pharma”,Lucene 不会给我任何结果。

我尝试在 searchStr 的末尾添加一个“*”,尝试将短语传递给通配符查询(在单个单词上工作正常,但在多个单词上失败)。

此外,我想添加一些模糊性,以便可以处理拼写错误,我是 Lucene 的新手,不知道从这里开始做什么,所以无论如何请帮助我!

PS 它的 Lucene …

java lucene

7
推荐指数
1
解决办法
551
查看次数

标签 统计

java ×1

lucene ×1