【问题标题】:Lucene indexing and searching at the same timeLucene 索引和搜索同时进行
【发布时间】:2025-12-06 03:30:01
【问题描述】:

我想在索引上使用 Lucene 进行搜索。索引经常更改。所以我需要做一些事情来同时搜索和索引。它是 Tomcat 上的 Web 应用程序。我想使用 RAMDeirectory 来提高搜索速度。我不知道该怎么做!

【问题讨论】:

    标签: java search tomcat lucene indexing


    【解决方案1】:

    miscLucene 包中的NRTManager 提供了同时搜索和索引的能力。

    TrackingIndexWriter writer; // your writer
    SearcherFactory factory = new SearcherFactory();
    NRTManager mgr = new NRTManager(writer, factory);
    

    查看 NRTManager 方法了解更多信息。

    【讨论】:

      【解决方案2】:

      您可以使用相同的索引同时搜索和索引。看看Lucene的near real time search

      来自 wiki 的一些示例代码,

      IndexWriter writer; // create an IndexWriter here
      Document doc = null; // create a document here
      writer.addDocument(doc); // update a document
      IndexReader reader = writer.getReader(); // get a reader with the new doc
      Document addedDoc = reader.document(0);
      

      【讨论】:

      • 那么我该如何搜索那个索引!?
      【解决方案3】:

      你必须这样做

      1. 批量/隔夜操作重建索引。
      2. 采用这种异步方式....

      取决于要求,您需要什么延迟。

      【讨论】:

      • 如何在不关闭网络应用程序的情况下交替索引!?