org.apache.lucene.document

Class DateField

public class DateField extends Object

Deprecated: If you build a new index, use DateTools instead. For existing indices you can continue using this class, as it will not be removed in the near future despite being deprecated.

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 RangeQuery 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.

Method Summary
static StringdateToString(Date date)
Converts a Date to a string suitable for indexing.
static StringMAX_DATE_STRING()
static StringMIN_DATE_STRING()
static DatestringToDate(String s)
Converts a string-encoded date into a Date object.
static longstringToTime(String s)
Converts a string-encoded date into a millisecond time.
static StringtimeToString(long time)
Converts a millisecond time to a string suitable for indexing.

Method Detail

dateToString

public static String dateToString(Date date)
Converts a Date to a string suitable for indexing.

Throws: RuntimeException if the date specified in the method argument is before 1970

MAX_DATE_STRING

public static String MAX_DATE_STRING()

MIN_DATE_STRING

public static String MIN_DATE_STRING()

stringToDate

public static Date stringToDate(String s)
Converts a string-encoded date into a Date object.

stringToTime

public static long stringToTime(String s)
Converts a string-encoded date into a millisecond time.

timeToString

public static String timeToString(long time)
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

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.