Winton Davies wrote:
>   I've an index that should fit in RAM -- but I need it stored as a
> file. Is there anyway to read in the regular directory in the the
> RAMDirectory and then create an IndexSearcher from this ? It seems
> that there should be, but I can't find a method to construct a
> RAMDirectory from a regular Directory ?

Look at IndexWriter.addIndexes( Directory[] dirs )

You can store your RAMDirectory into a new FSDirectory and load a
FSDircetory into a new RAMDirectory.

Something like: 

Directory loadIndex() {
        Directory fs = FSDirectory.getDirectory( pathToIndex, false );
        RAMDirectory ramdir = new RAMDircetory();
        IndexWriter iw = new IndexWriter( ramdir, myAnalyzer, false );
        iw.addIndexes( new Directory[]{fs} );
        iw.close();
        fs.close();
        return ramdir;
}
void storeIndex( Directory ramdir ) {
        Directory fs = FSDirectory.getDirectory( pathToIndex, true ); // create
a new Index here
        IndexWriter iw = new IndexWriter( fs, myAnalyzer, true );
        iw.addIndexes( new Directory[]{ramdir} );
        iw.close();
        fs.close();
}


HTH,
Gerhard

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to