java.lang.Object | |
↳ | org.apache.lucene.document.DateField |
This class is deprecated.
If you build a new index, use DateTools
or
NumericField
instead.
This class is included for use with existing
indices and will be removed in a future release (possibly Lucene 4.0).
Provides support for converting dates to strings and vice-versa. The strings are structured so that lexicographic sorting orders by date, which makes them suitable for use as field values and search terms.
Note that this class saves dates with millisecond granularity,
which is bad for TermRangeQuery
and PrefixQuery
, as those
queries are expanded to a BooleanQuery with a potentially large number
of terms when searching. Thus you might want to use
DateTools
instead.
Note: dates before 1970 cannot be used, and therefore cannot be
indexed when using this class. See DateTools
for an
alternative without such a limitation.
Another approach is NumericUtils
, which provides
a sortable binary representation (prefix encoded) of numeric values, which
date/time are.
For indexing a Date or Calendar, just get the unix timestamp as
long
using getTime()
or getTimeInMillis()
and
index this as a numeric value with NumericField
and use NumericRangeQuery
to query it.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Converts a Date to a string suitable for indexing.
| |||||||||||
Converts a string-encoded date into a Date object.
| |||||||||||
Converts a string-encoded date into a millisecond time.
| |||||||||||
Converts a millisecond time to a string suitable for indexing.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Converts a Date to a string suitable for indexing.
RuntimeException | if the date specified in the method argument is before 1970 |
---|
Converts a millisecond time to a string suitable for indexing.
RuntimeException | if the time specified in the method argument is negative, that is, before 1970 |
---|