Lucene中DateField的Date限制
在实际使用在发现Lunene中对利用时间范围做查询时是有限制的.也就是说要查询的时间不可能无穷的小,也不可能无穷的大.在他的文档中可以找到这句话:
org.apache.lucene.document.DataField
dates before 1970 cannot be used, and therefore cannot be indexed when using this class
1970是格林尼治时间的开始.如果需要被加如索引的时间在1970年之前,则不能使用.
再来看看的源码
package org.apache.lucene.document;
import java.util.Date;
public class DateField {
private DateField() {}
// make date strings long enough to last a millenium
private static int DATE_LEN = Long.toString(1000L*365*24*60*60*1000,
Character.MAX_RADIX).length();
public static String MIN_DATE_STRING() {
return timeToString(0);
}
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);
}
/**
* Converts a Date to a string suitable for indexing.
* @throws RuntimeException if the date s
posts - 0, comments - 0, trackbacks - 0, articles - 0
Copyright © suncjh