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

2023-06-28Java开发问题
16

本文介绍了在 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 搜索日期范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13