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).@Deprecated
public class DateField
extends java.lang.Object
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 Date.getTime()
or Calendar.getTimeInMillis()
and
index this as a numeric value with NumericField
and use NumericRangeQuery
to query it.
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
dateToString(java.util.Date date)
Deprecated.
Converts a Date to a string suitable for indexing.
|
static java.lang.String |
MAX_DATE_STRING()
Deprecated.
|
static java.lang.String |
MIN_DATE_STRING()
Deprecated.
|
static java.util.Date |
stringToDate(java.lang.String s)
Deprecated.
Converts a string-encoded date into a Date object.
|
static long |
stringToTime(java.lang.String s)
Deprecated.
Converts a string-encoded date into a millisecond time.
|
static java.lang.String |
timeToString(long time)
Deprecated.
Converts a millisecond time to a string suitable for indexing.
|
public static java.lang.String MIN_DATE_STRING()
public static java.lang.String MAX_DATE_STRING()
public static java.lang.String dateToString(java.util.Date date)
java.lang.RuntimeException
- if the date specified in the
method argument is before 1970public static java.lang.String timeToString(long time)
java.lang.RuntimeException
- if the time specified in the
method argument is negative, that is, before 1970public static long stringToTime(java.lang.String s)
public static java.util.Date stringToDate(java.lang.String s)
Copyright © 2000-2024 Apache Software Foundation. All Rights Reserved.