How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
问题描述
我想知道如何使用 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.
推荐答案
您应该使用使用 from 和 to 的范围查询.
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.
这篇关于如何在日期之间搜索(休眠搜索)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在日期之间搜索(休眠搜索)?
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
