简体   繁体   English

使用Java中的Lucene搜索日期范围?

[英]Searching on date ranges with Lucene in Java?

Is it possible to search on date ranges using Lucene in Java? 是否可以使用Java中的Lucene搜索日期范围? How do I build Lucene search queries based on date fields and dates ranges? 如何根据日期字段和日期范围构建Lucene搜索查询? For example: 例如:

  • between specified dates 在指定日期之间
  • prior to a specified date 在指定日期之前
  • after a specified date 在指定日期之后
  • within the last 24 hours 在过去的24小时内
  • within the past week 在过去的一周内
  • within the past month. 在过去一个月内。

[Edit] 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.4.1,我的系统真的很遗产,测试真的很差,所以如果可能的话我不想升级

Lucene (before version 2.9 anyway) only stores String values, and it only supports lexicographical range queries on that data. Lucene(无论如何在版本2.9之前)仅存储String值,并且它仅支持对该数据的词典范围查询。 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. 因此,如果要在其上存储日期/时间数据和执行范围查询,则需要以使其按字典顺序排序的方式显式格式化数据/时间值。

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] 例如,将您的日期/时间存储为类似2009-10-29T15:34:00 ,然后执行范围查询,如[2009-10-29T15:00:00 TO 2009-10-29T16:00:00]

As has been pointed out elsewhere, Lucene 2.9 finally introduced support for range queries against non-string data, making this all rather easier. 正如其他地方所指出的,Lucene 2.9最终引入了对非字符串数据的范围查询的支持,使这一切变得相当容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM