How to search between dates (Hibernate Search)?

后端 未结 1 1479
野的像风
野的像风 2020-12-18 08:55

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

相关标签:
1条回答
  • 2020-12-18 09:10

    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.

    0 讨论(0)
提交回复
热议问题