gpt4 book ai didi

hibernate - 在 hibernate 搜索中组合查询

转载 作者:行者123 更新时间:2023-12-03 08:01:05 24 4
gpt4 key购买 nike

在 Hibernate Search (lucene) 中是否有可能结合两个不同的查询。例如,当我想搜索 2 个应具有一个相应匹配值的字段时:

firstname - John
lastname - Doe

qBuilder.keyword().onField("firstname").matching("John").createQuery());
qBuilder.keyword().onField("lastname").matching("Doe").createQuery());

是一种从这个查询中进行的方法吗?

最佳答案

注:这有效,但对于更多 Hibernate-esque 方法,请参阅我的其他答案
createQuery()返回一个标准的 Lucene Query .因此,在 Lucene 中合并两个查询的典型方法是使用 BooleanQuery :

Query query1 = qBuilder.keyword().onField("firstname").matching("John").createQuery();
Query query2 = qBuilder.keyword().onField("lastname").matching("Doe").createQuery();
BooleanQuery bq = new BooleanQuery();
//Assuming you want to require a match on both first and last names.
//If a match on either is enough, use BooleanClause.Occur.SHOULD
bq.add(new BooleanClause(query1, BooleanClause.Occur.MUST));
bq.add(new BooleanClause(query2, BooleanClause.Occur.MUST));

关于hibernate - 在 hibernate 搜索中组合查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17501001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com