Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

java - How to search between dates (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;

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...