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

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

问题描述

我想知道如何使用 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.

推荐答案

您应该使用使用 fromto 的范围查询.

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.

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

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