how to integrate RAMDirectory into FSDirectory in lucene

前端 未结 1 943
-上瘾入骨i
-上瘾入骨i 2021-01-06 11:56

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

相关标签:
1条回答
  • 2021-01-06 11:59

    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.

    Like this:

    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;
    }
    
    0 讨论(0)
提交回复
热议问题