lucene-利用內存中索引和多線程提高索引效率


轉載地址: http://hi.baidu.com/idoneing/item/bc1cb914521c40603e87ce4d

1、RAMDirectory和FSDirectory對比

RAMDirectory在內存中所進行的操作比FSDirectory在磁盤上所完成的工作要快得多。

2、即使使用索引參數來使Lucene減少在磁盤上合並段的頻率,基於FSDirectory的索引還要把它們寫入磁盤,而RAMDirectory完全不用寫磁盤。

3、將RAMDirectory做為一個緩沖器實現對索引的、批處理

1)創建一個基於FSDirectory的索引。

FSDirectoryfsdir=FSDirectory.getDirectory("/tmp/index",true);

2)創建一個基於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中的所有數據寫入FSDirectory

if (可以寫入)

{

fswriter.addIndexes(Directory[] {ramdir});//合並數據

ramwriter.close();

ramwriter=newIndexWriter(ramdir,new SimpleAnalyzer(),true);

}

5)轉到第三步

4、並行索引多個索引文件

可以使用多線程的索引程序,並行使用把RAMDirectory作為一個緩沖器,然后使用addIndexes合並寫入


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM