如何在日期之间进行搜索(Hibernate Search)? [英] How to search between dates (Hibernate Search)?

查看:157
本文介绍了如何在日期之间进行搜索(Hibernate Search)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在Hibernate Search中使用Range-Query搜索日期,或者是否有我必须实现的过滤器。以下是我在记录实体中的字段

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.

推荐答案

使用 查询

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.

这篇关于如何在日期之间进行搜索(Hibernate Search)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆