How to search between dates (Hibernate Search)?

♀尐吖头ヾ 提交于 2019-11-27 06:14:50

问题


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;

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.


回答1:


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();

The ignoreFieldBridge is needed since you create the string based search string yourself using DateTools.



来源:https://stackoverflow.com/questions/12812093/how-to-search-between-dates-hibernate-search

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