我使用lucene进行了第一次聚合尝试,并通过app.config文件设定其优化时机和方法:
if(deletedItemIDs==null) deletedItemIDs = new Queue(config.RssIndexMinMergeDocs);
//deletedItemIDs用于保存需要更新的documentID
deletedItemIDs.Enqueue(item.Item.id);
this.RssIndexWriter.AddDocument(item.GetDocument());//indexwriter.
int doccount = RssIndexWriter.DocCount();
if(doccount % config.RssIndexMinMergeDocs == 0)//每隔config.RssIndexMinMergeDocs个优化一次
{
while(deletedItemIDs.Count>0)
{//对于需要更新的处理
string id = deletedItemIDs.Dequeue() as String;
RssIndexReader.Delete(new Lucene.Net.Index.Term(IndexedFeedItem.FN_ItemID,id));
}
RssIndexReader.Close();//关闭RssIndexReader.
RssIndexWriter.Optimize();//执行优化
RssIndexReader = IndexReader.Open(config.RssIndexPath);//重新打开RssIndexReader.
}