需求:
1.索引N天之内的信息
2.索引最新的多少篇文章信息
注:由于信息量比较大,重建索引比较花时间太长。
解决方案:
1.单索引解决方案:
对所有的信息进行增量索引, 在索引中加入时间轴信息或者文章ID信息。然后定期批量删除掉N天之前或者哪个ID之前的信息
2.多索引搜索解决:
在建立索引的时候按天或者按ID分别建立不同的索引目录,例如: ~/indexpath/20090817,~/indexpath/20090818……或者~/indexpath/id-200-300,~/indexpath/id-500-600……。在搜索的时候按照需要进行组合索引搜索
个人比较推荐后者,因为它更加的灵活,简单,效率更高。
multisearcher示例code:
ArrayList
Calendar cal = Calendar.getInstance();
String dname = "";
String path = "";
int n=7; //最近一周的索引
for(int i=0;i
cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) -i);
dname = DateFormat.getDateInstance().format(cal.getTime());
path = this.props.getProperty("index.directory") + "/" + dname;
try{
as.add(new IndexSearcher(IndexReader.open(path)));
}catch(Exception e){
logger.error(e.getStackTrace());
}
}
searcher = new MultiSearcher(as.toArray(new IndexSearcher[0]));
searcher.search(request);
.........

沙发