Hibernate QueryBuilder如何模仿'like'查询 [英] Hibernate QueryBuilder how to mimic 'like' query

查看:844
本文介绍了Hibernate QueryBuilder如何模仿'like'查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在学习这个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搜索,那么我认为您正在寻找通配符查询。

检查相关文件 there 第5.1.2.3节



所以你的代码将变成:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆