本文介紹了如何在日期之間搜索(休眠搜索)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想知道如何使用 Range-Query 在 Hibernate Search 中按日期搜索,或者是否有任何過濾器我必須實現.以下是我在記錄實體中的字段
I am wondering how I can search between by dates in Hibernate Search using Range-Query or is there any filter I have to implement.Following is my field in Record Entity
/**
* When the analysis started.
*/
@Temporal(TemporalType.TIMESTAMP)
@Field(index = Index.UN_TOKENIZED)
@DateBridge(resolution = Resolution.MILLISECOND)
private Date startTS;
我的要求是找到兩個日期之間分析的記錄,例如.2011 年 11 月 11 日到 2012 年 11 月 11 日.我很困惑如何做到這一點.
My requirment is to find the records analysed between a two dates eg. 11/11/2011 to 11/11/2012.I am confused how to do this.
推薦答案
您應該使用使用 from 和 to 的范圍查詢.
You should use a range query using from and to.
query = monthQb
.range()
.onField( "startTS" ).ignoreFieldBridge()
.from( DateTools.dateToString( from, DateTools.Resolution.MILLISECOND ) )
.to( DateTools.dateToString( to, DateTools.Resolution.MILLISECOND ) ).excludeLimit()
.createQuery();
ignoreFieldBridge 是必需的,因為您自己使用 DateTools 創建了基于字符串的搜索字符串.
The ignoreFieldBridge is needed since you create the string based search string yourself using DateTools.
這篇關于如何在日期之間搜索(休眠搜索)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!