Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>Directory.copy()</code> overwrites the destination directory, you need to use <code>IndexWriter.addIndexes()</code> to merge the new directory indices into the main one.</p> <p>You can also just re-open the main index and add documents to it directly. A RAMDirectory isn't necessarily more efficient than properly tuned buffer and merge factor settings (see <code>IndexWriter</code> docs).</p> <p>Update: instead of <code>Directory.copy()</code> you need to open <code>ramDir</code> for reading and <code>indexDir</code> for writing and call <code>.addIndexes</code> on the <code>indexDir</code> writer and pass it the <code>ramDir</code> reader. Alternatively, you can use <code>.addIndexesNoOptimize</code> and pass it <code>ramDir</code> directly (without opening a reader) and optimize the index before closing.</p> <p>But really, it's probably easier to just skip the RAMDir and open a writer on <code>indexDir</code> in the first place. Will make it easier to update changed files as well.</p> <p><strong>Example</strong></p> <pre><code>private int index(File indexDir, File dataDir, String suffix) throws Exception { RAMDirectory ramDir = new RAMDirectory(); IndexWriter indexWriter = new IndexWriter(ramDir, new StandardAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED); indexWriter.setUseCompoundFile(false); indexDirectory(indexWriter, dataDir, suffix); int numIndexed = indexWriter.maxDoc(); indexWriter.optimize(); indexWriter.close(); IndexWriter index = new IndexWriter(FSDirectory.open(indexDir), new StandardAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED); index.addIndexesNoOptimize(ramDir); index.optimize(); index.close(); return numIndexed; } </code></pre> <p>But, just this is fine too:</p> <pre><code>private int index(File indexDir, File dataDir, String suffix) throws Exception { IndexWriter index = new IndexWriter(FSDirectory.open(indexDir), new StandardAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED); // tweak the settings for your hardware index.setUseCompoundFile(false); index.setRAMBufferSizeMB(256); index.setMergeFactor(30); indexDirectory(index, dataDir, suffix); index.optimize(); int numIndexed = index.maxDoc(); index.close(); // you'll need to update indexDirectory() to keep track of indexed files return numIndexed; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload