如果我在类的同一个字段上指定两种类型的搜索(匹配和模糊),如下所示:
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();
qb.bool().should(qb.keyword().onField("name").matching(searchQuery).createQuery())
.should(qb.keyword().fuzzy().withPrefixLength(1).onField("name").matching(searchQuery).createQuery());
上述搜索最终会是:
MATCHING searchQuery against "name" OR Fuzzy searchQuery against "name"
答案 0 :(得分:3)
我相信你最后可能会错过createQuery()
,但除此之外,对我来说看起来很合理,但你可以自己检查一下。一旦创建了最终查询,只需使用Query.toString()
方法,只要您熟悉Lucene查询解析器语法,就可以为您提供查询的人类可读表示。像:
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();
Query query = qb.bool()
.should(qb.keyword().onField("name").matching(searchQuery).createQuery())
.should(qb.keyword().fuzzy().withPrefixLength(1).onField("name").matching(searchQuery).createQuery())
.createQuery();
System.out.println(query.toString())
//Or however you like to output debugging information...