|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.lucene.document.DateField
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 you do not have to use this class, you can just save your
dates as strings if lexicographic sorting orders them by date. This is
the case for example for dates like yyyy-mm-dd hh:mm:ss
(of course you can leave out the delimiter characters to save some space).
The advantage with using such a format is that you can easily save dates
with the required granularity, e.g. leaving out seconds. This saves memory
when searching with a RangeQuery or PrefixQuery, as Lucene
expands these queries to a BooleanQuery with potentially very many terms.
Note: dates before 1970 cannot be used, and therefore cannot be indexed when using this class.
Method Summary | |
static java.lang.String |
dateToString(java.util.Date date)
Converts a Date to a string suitable for indexing. |
static java.lang.String |
MAX_DATE_STRING()
|
static java.lang.String |
MIN_DATE_STRING()
|
static java.util.Date |
stringToDate(java.lang.String s)
Converts a string-encoded date into a Date object. |
static long |
stringToTime(java.lang.String s)
Converts a string-encoded date into a millisecond time. |
static java.lang.String |
timeToString(long time)
Converts a millisecond time to a string suitable for indexing. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
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)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |