简体   繁体   English

休眠搜索:精确短语匹配

[英]Hibernate search : exact phrase matching

Using Hibernate Search, I cannot manage to search for an exact sentence. 使用休眠搜索,我无法搜索确切的句子。

For instance, having the following sentences in my index : 例如,我的索引中包含以下句子:

1 - New York weather
2 - New York

I want to get only the line 2 matching "New York", so I make the following query : 我只想获取匹配“纽约”的第2行,因此我进行了以下查询:

qb.phrase().onField("label").sentence("New York").createQuery()

But this query returns both "New York" and "New York weather", ie my sentence is used like a prefix when I would like to use it like an equals. 但是此查询同时返回“纽约”和“纽约天气”,即当我想将其用作等号时,我的句子用作前缀。

How to do this using hibernate search ? 如何使用休眠搜索做到这一点?

Under 5.1.2.4 it mentions a 'slop factor' 在5.1.2.4中,它提到了“倾斜因子”

https://docs.jboss.org/hibernate/search/4.1/reference/en-US/html_single/#search-query-querydsl https://docs.jboss.org/hibernate/search/4.1/reference/en-US/html_single/#search-query-querydsl

Try a slop factor of zero? 尝试倾斜系数为零?

qb.phrase().withSlop(0).onField("label").sentence("New York").createQuery() qb.phrase()。withSlop(0).onField(“ label”)。sentence(“ New York”)。createQuery()

also try using the Lucene API as mentioned in this question. 也请尝试使用此问题中提到的Lucene API。

Finding exact match using Lucene search API 使用Lucene搜索API查找完全匹配

Your use case is a straight forward one and probably doesn't warrant the Hibernate Search query DSL 您的用例很简单,可能不保证Hibernate Search查询DSL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM