是否可以在 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:
我使用的是 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 搜索日期范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)