Mailing List Archive

Moving an index from one Directory to another?
To improve speed for our application, I'm trying to move our index
from the disk to a RAM directory when our database is opened, and
move it back to the disk when the database is closed. The code looks
something like this:

-----open-----
Directory diskDirectory = FSDirectory.getDirectory(indexPath, false);
if (keepInRAM)
{
indexDirectory = new RAMDirectory();
try
{
IndexWriter ramWriter = new
IndexWriter(indexDirectory, analyzer, true);
ramWriter.addIndexes(new Directory[]
{diskDirectory}); // load into RAM
ramWriter.close();
diskDirectory = FSDirectory.getDirectory(indexPath,
true); // erase the disk copy
indexInRAM = true;
}
catch (Exception e)
{
indexInRAM = false;
indexDirectory = diskDirectory;
}
}
else
{
indexInRAM = false;
indexDirectory = diskDirectory;
}
-----open-----

-----close-----
if (indexInRAM)
{
try
{
IndexWriter diskWriter = new IndexWriter(indexPath,
analyzer, true);
diskWriter.addIndexes(new Directory[]
{indexDirectory}); // write out to disk
diskWriter.close();
}
catch (Exception e)
{
// ...
}
}
-----close-----

There's only one problem--it's not working.

I have an index on disk. If I search it when it's on the disk, I get
results. If I try to load it into memory, I don't get any results
when I search. Similarly, if I add documents to the index while in
memory and try to write it to disk, I get an empty index (just the
"segments" file) in the index.

Code almost identical to this has been posted before to the list, and
I don't see where I'm going wrong here. I'd appreciate any help. (I'm
using RC4.)

Thanks.

Avi

--
Avi Drissman
avi_drissman@baseview.com
Argh! This darn mailserver is trunca

--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>