Hi,

I am trying to use RAMDirectory as a buffer and am having some problems. I
create indexes using FSDirectory directly and index directory contains the
following files:

bash-3.00$ ls ~/index/

_0.cfs  segments_3  segments.gen

 

 

When I am trying to use RAMDirectory as a buffer and then add indexes to a
FSDirectory the directory looks like:

-bash-3.00$ ls ~/index/

segments_1  segments.gen

 

and search is failing.

 

This is a code I use to do it:

import org.apache.lucene.analysis.standard.StandardAnalyzer;

import org.apache.lucene.document.Document;

import org.apache.lucene.document.Field;

import org.apache.lucene.index.IndexWriter;

import org.apache.lucene.store.Directory;

import org.apache.lucene.store.FSDirectory;

import org.apache.lucene.store.RAMDirectory;

import java.io.FileReader;

 

class Test {

  public static void main(String[] args) throws Exception{

         FSDirectory fsDir= FSDirectory.getDirectory(args[0]);

         RAMDirectory ramDir=new RAMDirectory();

         IndexWriter fsWriter=new IndexWriter(fsDir,new
StandardAnalyzer(),true);

         IndexWriter ramWriter=new IndexWriter(ramDir,new
StandardAnalyzer(),true);

         Document doc=new Document();

         doc.add(new Field("test","I am testing RAM directory",
Field.Store.YES, Field.Index.UN_TOKENIZED));

         doc.add(new Field("contents", new
FileReader(args[1]),Field.TermVector.WITH_POSITIONS_OFFSETS ) );

         ramWriter.addDocument(doc);

         fsWriter.addIndexes(new Directory[] {ramDir,});

         ramWriter.close();

         fsWriter.optimize();

         fsWriter.close();

  }

}

 

 

To run it  just create index directory and do: 

 

 java Test  <index_dir_name> <some_file_name>

 

 

Any idea?

Thanks a lot,

Tanya

Reply via email to