org.apache.lucene.document
public class: DateField [javadoc |
source]
java.lang.Object
org.apache.lucene.document.DateField
Deprecated! If - you build a new index, use
DateTools instead. This class is included for use with existing
indices and will be removed in a future release.
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 from org.apache.lucene.document.DateField Detail: |
public static String MAX_DATE_STRING() {
char[] buffer = new char[DATE_LEN];
char c = Character.forDigit(Character.MAX_RADIX-1, Character.MAX_RADIX);
for (int i = 0 ; i < DATE_LEN; i++)
buffer[i] = c;
return new String(buffer);
} Deprecated! |
public static String MIN_DATE_STRING() {
return timeToString(0);
} Deprecated! |
public static String dateToString(Date date) {
return timeToString(date.getTime());
} Deprecated!Converts a Date to a string suitable for indexing. |
public static Date stringToDate(String s) {
return new Date(stringToTime(s));
} Deprecated!Converts a string-encoded date into a Date object. |
public static long stringToTime(String s) {
return Long.parseLong(s, Character.MAX_RADIX);
} Deprecated!Converts a string-encoded date into a millisecond time. |
public static String timeToString(long time) {
if (time < 0)
throw new RuntimeException("time '" + time + "' is too early, must be >= 0");
String s = Long.toString(time, Character.MAX_RADIX);
if (s.length() > DATE_LEN)
throw new RuntimeException("time '" + time + "' is too late, length of string " +
"representation must be < = " + DATE_LEN);
// Pad with leading zeros
if (s.length() < DATE_LEN) {
StringBuffer sb = new StringBuffer(s);
while (sb.length() < DATE_LEN)
sb.insert(0, 0);
s = sb.toString();
}
return s;
} Deprecated!Converts a millisecond time to a string suitable for indexing. |