Issues concerning DateRangeQueries


Using a Filter Instead

Using indexed hierarchical prefixes

When the above advice does not help enough, consider indexing a date CCYYMMDD as multiple prefixes on the same index positions:


and use the fewest prefixes possible to search for a range. For example to search for every date in the 1990's, search for 199. To search for the date range Jan 2007 up to and including Jan 2008, search for (2007 OR 200801).

A similar scheme can be used for general numerical range searching. This trades off index size for search performance.

A generalization of this is available in NumericRangeQuery in Lucene Core 2.9. This works by mapping values to be indexed to a 64 bit long value, and by indexing various length prefixes of these 64 bit values. Order preserving mappings for dates and floating points are available. See SearchNumericalFields.

When longer dates or numbers need to be indexed, for example CCYYMMDDhhmmss with hours, minutes and seconds added, consider indexing the hhmmss separately, possibly with hierarchical prefixes themselves. A search with CCYYMMDDhhmmss accuracy would then need a BooleanQuery with required clauses for the CCYYMMDD and hhmmss parts.

DateRangeQueries (last edited 2009-10-07 06:08:11 by UweSchindler)