If you need to reprint it, please indicate the source and author. Thank you.
QQ: 221704
MSN: flyly@yeah.net
Email: zhangfl@sports.cn
In actual use, there is a limit on the use of time range for query in lunene. that is to say, the query time cannot be infinitely small or infinitely large. this sentence can be found in his document:
Org.apache.e.doc ument. datafield
Dates before 1970 cannot be used, and therefore cannot be indexed when using this class
1970 is the start of Greenwich Mean Time. If you want to add an index before January 1, 1970, it cannot be used.
Let's take a look at the source code.
Package org.apache.e.doc ument;
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 x 365x24x60x60x1000,
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 specified in
* Method argument is before 1970
*/
Public static string datetostring (date ){
Return timetostring (date. gettime ());
}
/**
* Converts a millisecond time to a string suitable for indexing.
* @ Throws runtimeexception if the time specified in
* Method argument is negative, that is, before 1970
*/
Public static string timetostring (long time ){
If (time <0)
Throw new runtimeexception ("time too early ");
String S = long. tostring (time, character. max_radix );
If (S. Length ()> date_len)
Throw new runtimeexception ("time too late ");
// 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;
}
/** Converts a string-encoded date into a millisecond time .*/
Public static long stringtotime (string s ){
Return long. parselong (S, character. max_radix );
}
/** Converts a string-encoded date into a date object .*/
Public static date stringtodate (string s ){
Return new date (stringtotime (s ));
}
}
Is it depressing? I don't know why the author wants to impose such restrictions. java. util. Date class restrictions can be implemented by 1900 (I have not verified it. If not, I can make a brick for everyone ).
However, the advantage of open-source is that you can change the source code.
PS: the purpose of the modification is to make time indexes for some images of the Ninth Five-Year Plan. If there is no such requirement, you do not need to modify it. I think the author should have his reasons for limiting this. ask him at maillist another day.