Searching on date ranges with Lucene in Java?(在 Java 中使用 Lucene 搜索日期范围?)
问题描述
是否可以在 Java 中使用 Lucene 搜索日期范围?如何根据日期字段和日期范围构建 Lucene 搜索查询?例如:
Is it possible to search on date ranges using Lucene in Java? How do I build Lucene search queries based on date fields and dates ranges? For example:
- 在指定日期之间
- 在指定日期之前
- 在指定日期之后
- 过去 24 小时内
- 过去一周内
- 在过去一个月内.
我使用的是 Lucene 2.4.1,我的系统非常旧,而且测试非常糟糕,所以我希望尽可能不必升级
i'm using Lucene 2.4.1 and my system is really legacy and really poorly tested so i would like if possible not to have to upgrade
推荐答案
Lucene(无论如何在 2.9 版本之前)只存储字符串值,并且它只支持对该数据的字典范围查询.因此,如果您想存储日期/时间数据并对其执行范围查询,则需要明确格式化您的数据/时间值,使其按字典顺序排列.
Lucene (before version 2.9 anyway) only stores String values, and it only supports lexicographical range queries on that data. So if you want to store date/time data and performa range queries on it, you need to explicitly format your data/time values in such a way as to make them lexicographically ordered.
例如,将您的日期/时间存储为 2009-10-29T15:34:00 之类的内容,然后进行范围查询,例如 [2009-10-29T15:00:00TO 2009-10-29T16:00:00]
For example, store your date/times as something like 2009-10-29T15:34:00, and then do range queries like [2009-10-29T15:00:00 TO 2009-10-29T16:00:00]
正如其他地方所指出的,Lucene 2.9 最终引入了对非字符串数据范围查询的支持,这让这一切变得更加容易.
As has been pointed out elsewhere, Lucene 2.9 finally introduced support for range queries against non-string data, making this all rather easier.
这篇关于在 Java 中使用 Lucene 搜索日期范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Java 中使用 Lucene 搜索日期范围?
基础教程推荐
- RabbitMQ:消息保持“未确认"; 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
