Hibernate QueryBuilder how to mimic 'like' query

瘦欲@ 提交于 2019-12-12 03:57:41

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/15344896/hibernate-querybuilder-how-to-mimic-like-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!