1、RAMDirectory和FSDirectory對(duì)比
RAMDirectory在內(nèi)存中所進(jìn)行的操作比FSDirectory在磁盤上所完成的工作要快得多。
2、即使使用索引參數(shù)來使Lucene減少在磁盤上合并段的頻率,基于FSDirectory的索引還要把它們寫入磁盤,而RAMDirectory完全不用寫磁盤。
3、將RAMDirectory做為一個(gè)緩沖器實(shí)現(xiàn)對(duì)索引的、批處理
1)創(chuàng)建一個(gè)基于FSDirectory的索引。
FSDirectoryfsdir=FSDirectory.getDirectory("/tmp/index",true);
2)創(chuàng)建一個(gè)基于RAMDirectory的索引
RAMDirectory ramdir=new RAMDirectory();
3)向基于RAMDirectory的索引中增加文檔。
IndexWriter ramwriter=new IndexWriter(ramdir,newSimpleAnalyzer(),true);
IndexWriter fswriter=new IndexWriter(fsdir,newSimpleAnalyzer(),true);
while (...){
...
ramwriter.addDocument(doc);
}
4)不定期把緩存在RAMDirectory中的所有數(shù)據(jù)寫入FSDirectory
if (可以寫入)
{
fswriter.addIndexes(Directory[] {ramdir});//合并數(shù)據(jù)
ramwriter.close();
ramwriter=newIndexWriter(ramdir,new SimpleAnalyzer(),true);
}
5)轉(zhuǎn)到第三步
4、并行索引多個(gè)索引文件
可以使用多線程的索引程序,并行使用把RAMDirectory作為一個(gè)緩沖器,然后使用addIndexes合并寫入
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注