我正在尝试向我的搜索方法添加时间限制,这意味着按日期搜索。我知道 lucene 只能处理字符串,但我首先将日期转换为字符串。但它仍然不起作用,并且由于代码库的复杂性,我不太确定它为什么不起作用。这是一个简单的版本:
@Indexed
public class SomeDocument extends Document{
}
public abstract class Document extends BaseEntity{
}
@Indexed
public class BaseEntity {
@IndexedEmbedded
private Date lastUpdatedDate;
}
//snippet of search method
BooleanQuery bq = new BooleanQuery();
long oneDay = 1000L * 60 * 60 * 24;
long currentTime = System.currentTimeMillis();
Date dateOne = new Date(currentTime);
Date dateTwo = new Date(currentTime - (oneDay * 7)); // 1 week ago ago
TermRangeQuery dateQuery = new TermRangeQuery("lastUpdatedDate", dateTwo.toString(), dateOne.toString(), true, true);
bq.add(new BooleanClause(dateQuery, BooleanClause.Occur.MUST));
//more is added to boolean query, I create a full text query, and use the list() method
有没有人看到一个实施不正确的地方?谢谢!