java Hibernate搜索:精确短语匹配
使用Hibernate搜索,我无法搜索准确的句子
例如,在我的索引中有以下句子:
1 - New York weather
2 - New York
我只想得到与“纽约”匹配的第2行,因此我进行以下查询:
qb.phrase().onField("label").sentence("New York").createQuery()
但是这个查询同时返回“New York”和“New York weather”,也就是说,当我想将我的句子用作一个equals时,我的句子被用作前缀
如何使用hibernate搜索实现这一点
# 1 楼答案
在5.1.2.4中,它提到了一个“斜率系数”
https://docs.jboss.org/hibernate/search/4.1/reference/en-US/html_single/#search-query-querydsl
尝试将斜率因子设为零
qb。短语()。用slop(0)。onField(“标签”)。句子(“纽约”)。createQuery()
还可以尝试使用本问题中提到的Lucene API
Finding exact match using Lucene search API
您的用例是直截了当的,可能不支持Hibernate搜索查询DSL