<legend id='sxTdP'><style id='sxTdP'><dir id='sxTdP'><q id='sxTdP'></q></dir></style></legend>

    <small id='sxTdP'></small><noframes id='sxTdP'>

        <bdo id='sxTdP'></bdo><ul id='sxTdP'></ul>
    1. <i id='sxTdP'><tr id='sxTdP'><dt id='sxTdP'><q id='sxTdP'><span id='sxTdP'><b id='sxTdP'><form id='sxTdP'><ins id='sxTdP'></ins><ul id='sxTdP'></ul><sub id='sxTdP'></sub></form><legend id='sxTdP'></legend><bdo id='sxTdP'><pre id='sxTdP'><center id='sxTdP'></center></pre></bdo></b><th id='sxTdP'></th></span></q></dt></tr></i><div id='sxTdP'><tfoot id='sxTdP'></tfoot><dl id='sxTdP'><fieldset id='sxTdP'></fieldset></dl></div>

      1. <tfoot id='sxTdP'></tfoot>
      2. 如何在lucene中将RAMDirectory集成到FSDirectory

        时间:2023-09-29
        <i id='YdYSq'><tr id='YdYSq'><dt id='YdYSq'><q id='YdYSq'><span id='YdYSq'><b id='YdYSq'><form id='YdYSq'><ins id='YdYSq'></ins><ul id='YdYSq'></ul><sub id='YdYSq'></sub></form><legend id='YdYSq'></legend><bdo id='YdYSq'><pre id='YdYSq'><center id='YdYSq'></center></pre></bdo></b><th id='YdYSq'></th></span></q></dt></tr></i><div id='YdYSq'><tfoot id='YdYSq'></tfoot><dl id='YdYSq'><fieldset id='YdYSq'></fieldset></dl></div>
          1. <small id='YdYSq'></small><noframes id='YdYSq'>

            • <bdo id='YdYSq'></bdo><ul id='YdYSq'></ul>

              <legend id='YdYSq'><style id='YdYSq'><dir id='YdYSq'><q id='YdYSq'></q></dir></style></legend>

                <tfoot id='YdYSq'></tfoot>

                    <tbody id='YdYSq'></tbody>

                  本文介绍了如何在lucene中将RAMDirectory集成到FSDirectory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我现在有一个问题,这个是关于 lucene 的.我试图制作一个可以进行索引并将它们首先存储在内存中的 lucene 源代码使用 RAMDirectory,然后将内存中的该索引刷新到磁盘中使用 FSDirectory.我对这段代码做了一些修改,但是徒劳无功.也许你们中的一些人可以帮帮我.

                  I had a question now, this one regarding lucene. I was trying to make a lucene source code that can do indexing and store them first in a memory using RAMDirectory and then flush this index in a memory into a disk using FSDirectory. I had done some modifications of this code but to no avail. maybe some of you can help me out a bit.

                  那么对我来说,将 RAMDirectory 集成到此源中的最佳方式是什么?将它们放入 FSDirectory 之前的代码.任何帮助,将不胜感激尽管这是源代码.

                  so what's the best way for me to integrate RAMDirectory in this source code before putting them in FSDirectory. any help would be appreciated though here is the source code.

                  import org.apache.lucene.analysis.SimpleAnalyzer;
                  import org.apache.lucene.document.Document;
                  import org.apache.lucene.document.Field;
                  import org.apache.lucene.index.IndexWriter;
                  import org.apache.lucene.store.FSDirectory;
                  
                  import java.io.File;
                  import java.io.FileReader;
                  import java.io.IOException;
                  
                  public class SimpleFileIndexer {
                      public static void main(String[] args) throws Exception {
                          File indexDir = new File("C:/Users/Raden/Documents/lucene/LuceneHibernate/adi");
                          File dataDir = new File("C:/Users/Raden/Documents/lucene/LuceneHibernate/adi");
                          String suffix = "txt";
                          SimpleFileIndexer indexer = new SimpleFileIndexer();
                          int numIndex = indexer.index(indexDir, dataDir, suffix);
                          System.out.println("Total files indexed " + numIndex);
                      }
                  
                      private int index(File indexDir, File dataDir, String suffix) throws Exception {
                          IndexWriter indexWriter = new IndexWriter(
                                  FSDirectory.open(indexDir),
                                  new SimpleAnalyzer(),
                                  true,
                                  IndexWriter.MaxFieldLength.LIMITED);
                          indexWriter.setUseCompoundFile(false);
                          indexDirectory(indexWriter, dataDir, suffix);
                          int numIndexed = indexWriter.maxDoc();
                          indexWriter.optimize();
                          indexWriter.close();
                          return numIndexed;
                      }
                  
                      private void indexDirectory(IndexWriter indexWriter, File dataDir, String suffix) throws IOException {
                          File[] files = dataDir.listFiles();
                          for (int i = 0; i < files.length; i++) {
                              File f = files[i];
                              if (f.isDirectory()) {
                                  indexDirectory(indexWriter, f, suffix);
                              } else {
                                  indexFileWithIndexWriter(indexWriter, f, suffix);
                              }
                          }
                      }
                  
                      private void indexFileWithIndexWriter(IndexWriter indexWriter, File f, String suffix) throws IOException {
                          if (f.isHidden() || f.isDirectory() || !f.canRead() || !f.exists()) {
                              return;
                          }
                          if (suffix != null && !f.getName().endsWith(suffix)) {
                              return;
                          }
                          System.out.println("Indexing file " + f.getCanonicalPath());
                          Document doc = new Document();
                          doc.add(new Field("contents", new FileReader(f)));
                          doc.add(new Field("filename", f.getCanonicalPath(), Field.Store.YES, Field.Index.ANALYZED));
                          indexWriter.addDocument(doc);
                      }
                  }
                  

                  推荐答案

                  我不确定这样做是否会获得任何性能提升,但你可以在 RAMDirectory 上完成所有索引 然后将目录复制到 FSDirectory.

                  I'm not really sure that you'll get any performance gain from doing this, but you could do all the indexing on a RAMDirectory and then copy the directory to an FSDirectory.

                  像这样:

                  private int index(File indexDir, File dataDir, String suffix) throws Exception {
                      RAMDirectory ramDir = new RAMDirectory();          // 1
                      IndexWriter indexWriter = new IndexWriter(
                              ramDir,                                    // 2
                              new SimpleAnalyzer(),
                              true,
                              IndexWriter.MaxFieldLength.LIMITED);
                      indexWriter.setUseCompoundFile(false);
                      indexDirectory(indexWriter, dataDir, suffix);
                      int numIndexed = indexWriter.maxDoc();
                      indexWriter.optimize();
                      indexWriter.close();
                  
                      Directory.copy(ramDir, FSDirectory.open(indexDir), false); // 3
                  
                      return numIndexed;
                  }
                  

                  这篇关于如何在lucene中将RAMDirectory集成到FSDirectory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Lucene 搜索中匹配精确文本? 下一篇:如何以一种方法转义java中的一组特殊字符?

                  相关文章

                  最新文章

                    <bdo id='gItVN'></bdo><ul id='gItVN'></ul>
                  <tfoot id='gItVN'></tfoot>
                  1. <small id='gItVN'></small><noframes id='gItVN'>

                      <legend id='gItVN'><style id='gItVN'><dir id='gItVN'><q id='gItVN'></q></dir></style></legend>

                      <i id='gItVN'><tr id='gItVN'><dt id='gItVN'><q id='gItVN'><span id='gItVN'><b id='gItVN'><form id='gItVN'><ins id='gItVN'></ins><ul id='gItVN'></ul><sub id='gItVN'></sub></form><legend id='gItVN'></legend><bdo id='gItVN'><pre id='gItVN'><center id='gItVN'></center></pre></bdo></b><th id='gItVN'></th></span></q></dt></tr></i><div id='gItVN'><tfoot id='gItVN'></tfoot><dl id='gItVN'><fieldset id='gItVN'></fieldset></dl></div>