我正在尝试设置Lucene来处理存储在数据库中的一些文档.我从这个HelloWorld示例开始.但是,创建的索引不会保存在任何位置,每次运行程序时都需要重新创建.有没有办法保存Lucene创建的索引,以便每次程序启动时都不需要将文档加载到它中?
public class HelloLucene {
public static void main(String[] args) throws IOException, ParseException {
// 0. Specify the analyzer for tokenizing text.
// The same analyzer should be used for indexing and searching
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_35);
// 1. create the index
Directory index = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_35, analyzer);
IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Lucene in Action");
addDoc(w, "Lucene for Dummies");
addDoc(w, "Managing Gigabytes");
addDoc(w, "The Art of Computer Science");
w.close();
// 2. …Run Code Online (Sandbox Code Playgroud)