FSDirectory 与 RAMDirectory

//public IndexWriter(Directory d, Analyzer a, boolean create)
//中的Directory类型,在Lucene工具当中有两个子类分别是RAMDirectory 和 FSDirectory
//这两个目录度可以作为索引的存储路径
//RAMDirectory是存放到内存当中的一个区域,FSDirectory是存放到文件系统中的磁盘里
//虽然向其添加Document的过程与使用FSDDirectory一样,但是由于它是内存中的一块区域
//因此,如果不将RAMDirectory中的内存写入磁盘,当虚拟机退出后,里面的内容也会随之消失。
//一次需要将RAMDirectory中的内容转到FSDirectory中。
package directory;


import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory;


public class Fsd {
try{
//对FSDirectory 和 RAMDirectory的初始化过程。
RAMDirectory ramDir = new RAMDirectory();
FSDirectory fsDir = FSDirectory.getDirectory(INDEX_STORE_PATH, true);

IndexWriter fsWriter = new IndexWriter(fsDir, new StandardAnalyzer(), true);
IndexWriter ramWriter = new IndexWriter(ramDir, new StandardAnalyzer(), true);
}catch(Exception e)
{
e.printStackTrace();
}
}

你可能感兴趣的:(FSDirectory 与 RAMDirectory)