Class DateField
- java.lang.Object
-
- org.apache.lucene.document.DateField
-
@Deprecated public class DateField extends Object
Deprecated.If you build a new index, useDateToolsorNumericFieldinstead. 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
TermRangeQueryandPrefixQuery, as those queries are expanded to a BooleanQuery with a potentially large number of terms when searching. Thus you might want to useDateToolsinstead.Note: dates before 1970 cannot be used, and therefore cannot be indexed when using this class. See
DateToolsfor 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 aDateorCalendar, just get the unix timestamp aslongusingDate.getTime()orCalendar.getTimeInMillis()and index this as a numeric value withNumericFieldand useNumericRangeQueryto query it.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static StringdateToString(Date date)Deprecated.Converts a Date to a string suitable for indexing.static StringMAX_DATE_STRING()Deprecated.static StringMIN_DATE_STRING()Deprecated.static DatestringToDate(String s)Deprecated.Converts a string-encoded date into a Date object.static longstringToTime(String s)Deprecated.Converts a string-encoded date into a millisecond time.static StringtimeToString(long time)Deprecated.Converts a millisecond time to a string suitable for indexing.
-
-
-
Method Detail
-
MIN_DATE_STRING
public static String MIN_DATE_STRING()
Deprecated.
-
MAX_DATE_STRING
public static String MAX_DATE_STRING()
Deprecated.
-
dateToString
public static String dateToString(Date date)
Deprecated.Converts a Date to a string suitable for indexing.- Throws:
RuntimeException- if the date specified in the method argument is before 1970
-
timeToString
public static String timeToString(long time)
Deprecated.Converts a millisecond time to a string suitable for indexing.- Throws:
RuntimeException- if the time specified in the method argument is negative, that is, before 1970
-
stringToTime
public static long stringToTime(String s)
Deprecated.Converts a string-encoded date into a millisecond time.
-
-