Searching on date ranges with Lucene in Java?

前端 未结 1 635
面向向阳花
面向向阳花 2021-02-13 22:08

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:

  • between spec
1条回答
  •  有刺的猬
    2021-02-13 22:38

    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.

    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]

    As has been pointed out elsewhere, Lucene 2.9 finally introduced support for range queries against non-string data, making this all rather easier.

    0 讨论(0)
提交回复
热议问题