lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gerhard Schwarz <gerhard.schw...@fpg.de>
Subject Re: RAMdirectory from Directory ?
Date Wed, 14 Nov 2001 11:26:48 GMT
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:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>


Mime
View raw message