小编Swe*_*man的帖子

如何持久保存Lucene文档索引,以便每次程序启动时都不需要将文档加载到文档中?

我正在尝试设置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)

java lucene

1
推荐指数
2
解决办法
3346
查看次数

标签 统计

java ×1

lucene ×1