booleanjuntion#iSempty等效于休眠搜索6 booleanpredicateclausesstep
Hibernate Search 5 BooleanJunction具有有用的ISEMPTY()方法,您可以确定是否实际存在任何条款。这有助于在B/C上游构建查询时,我们将不包括,或者如果特定的布莱亚截止为空,则会更改我们的查询,因为它不会提供所需的结果。
Hibernate Search 6中布尔质量的等效物是什么?我看不到一个,那么是否有另一种方法可以确定布尔式PRELEANPREENATECATECLAUSESSTEP是空的还是其中没有条款?
提供一些示例代码以说明。
Hibernate Search 5.10.7. -Final:
public Query buildProbableVendorNamesQuery(FullTextSession fts, QueryBuilder qb, Set<String> vendorNames) {
BooleanJunction namesBool = qb.bool();
vendorNames.forEach(name ->
addProbableVendorNameBool(fts, qb, namesBool, name)
);
return namesBool.isEmpty() ? null : namesBool.createQuery();
}
Hibernate Search 6.1.5.Final:
public SearchPredicate buildProbableVendorNamesPredicate(SearchPredicateFactory pf, Set<String> vendorNames) {
BooleanPredicateClausesStep namesBool = pf.bool();
vendorNames.forEach(name ->
addProbableVendorNameBool(pf, namesBool, name)
);
//TODO: How can we know if namesBool is empty so we can return null?
return namesBool.toPredicate();
}
命名为空的原因有多种原因,1个名称本身最终成为停止字或将其标准化为一无所有。在这种情况下,我们想通知呼叫者在上游,搜索播放是无效的,因此不要尝试在查询中使用它。
Hibernate Search 5 BooleanJunction has a useful isEmpty() method to you can determine whether any clauses actually exist. This helps when building the Queries upstream b/c we won't include, or will alter our Query if a particular BooleanJunction is empty since it will not provide the results desired.
What is the equivalent for BooleanPredicateClausesStep in Hibernate Search 6? I don't see one, so is there another way to determine whether a BooleanPredicateClausesStep is empty or has no clauses contained within it?
Providing some example code to illustrate.
Hibernate Search 5.10.7.Final:
public Query buildProbableVendorNamesQuery(FullTextSession fts, QueryBuilder qb, Set<String> vendorNames) {
BooleanJunction namesBool = qb.bool();
vendorNames.forEach(name ->
addProbableVendorNameBool(fts, qb, namesBool, name)
);
return namesBool.isEmpty() ? null : namesBool.createQuery();
}
Hibernate Search 6.1.5.Final:
public SearchPredicate buildProbableVendorNamesPredicate(SearchPredicateFactory pf, Set<String> vendorNames) {
BooleanPredicateClausesStep namesBool = pf.bool();
vendorNames.forEach(name ->
addProbableVendorNameBool(pf, namesBool, name)
);
//TODO: How can we know if namesBool is empty so we can return null?
return namesBool.toPredicate();
}
There are various reasons why namesBool could be empty, 1 being that the name itself ended up being a stop word or normalizing down to nothing. In that case we'd want to inform the caller upstream that the SearchPredicate is null so don't attempt to use it in a query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:Hibernate Search 6.2.0.Alpha2在
booleanPredicateOptionsCollector
/booleanPrealPreadicateClausessTep
上引入了hascclause
方法,因此您应该使用它。上一个答案:
在冬眠搜索6.2之前,没有等效的。
同时,您可以将
list
传递给addprobablevendornamebool
作为解决方法。虽然不是很漂亮,但它会起作用:或者,如果您可以更改
addprobablevendornamebool
,以便它准确地返回一个谓词(例如,如果需要,请在必要时创建自己的布尔谓词)或null <<
null << /代码>:
EDIT: Hibernate Search 6.2.0.Alpha2 introduced a
hasClause
method onBooleanPredicateOptionsCollector
/BooleanPredicateClausesStep
, so you should use that.Previous answer:
Before Hibernate Search 6.2, there is no equivalent.
In the meantime, you can pass a
List
toaddProbableVendorNameBool
as a workaround. While not very pretty, it will work:Or, if you can change
addProbableVendorNameBool
so that it returns exactly exactly one predicate (e.g. by having it create its own boolean predicate if necessary) ornull
: