Hibernate QueryBuilder如何模仿'like'查询 [英] Hibernate QueryBuilder how to mimic 'like' query
问题描述
我现在正在学习这个API。我有一些代码如下,但它确实匹配,而不是'喜欢'。所以,当我有一个字符串 JMeter
,并使用 Meter
时,它不会将它带回搜索结果中,但这应该。任何帮助不胜感激
SearchManager searchManager = Search.getSearchManager(listingIndex);
QueryBuilder qb = searchManager.buildQueryBuilderForClass(ListingIndexEntry.class).get();
Query q = qb.keyword()。onField(title)。matching(title).createQuery();
谢谢
Karthik
如果您使用的是hibernate搜索,那么我认为您正在寻找通配符查询。
检查相关文件
所以你的代码将变成:
Query q = qb.keyword()。wildcard()。onField(title)。matching(*+ title).createQuery();
注意文档中指定的性能,从通配符开始并不是很好。 p>
I am learning this API now. I have some code as below, but it does an exact match instead of a 'like'. So when I have a String JMeter
, and I use Meter
, it does not bring it back in the search result but it should. Any help greatly appreciated
SearchManager searchManager = Search.getSearchManager(listingIndex);
QueryBuilder qb = searchManager.buildQueryBuilderForClass(ListingIndexEntry.class).get();
Query q = qb.keyword().onField("title").matching(title).createQuery();
Thank you
Karthik
If you are using hibernate search then I think you are looking for wildcard queries.
Check the documentation about it there section 5.1.2.3
So your code will become :
Query q = qb.keyword().wildcard().onField("title").matching("*"+title).createQuery();
Watchout for the performance as specified in the documentation, starting with a wildcard is not very good.
这篇关于Hibernate QueryBuilder如何模仿'like'查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!