You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by "xing@mac.com" <xi...@mac.com> on 2005/07/09 08:44:57 UTC

Loading FS index into RAM index

I was reading the Lucene book and came across the part where the author 
detailed how to write index to ram dir and then flush it to file dir.

That turned on a light bulb and I want to do bidirectional index 
loading. Build index in ram, store in file for backup. Then if I have to 
shutdown the process, I can then ask it to reload the index from file 
back into ram for searching duties.

Unforunately my code below which tries to load fs index into ram fails 
right at "ram_writer.addIndexes(fs_dir);" with io exception. When I 
check "/tmp/lucene-index/", which contains a proper index,  after the io 
exception everything was erased and the directory was empty.

Thanks for any pointers.

Xing


try {
		System.out.println("start");
		//IndexWriter file_writer = new IndexWriter("/tmp/lucene-index/", new 
StandardAnalyzer(), true);
		IndexWriter ram_writer = new IndexWriter(new RAMDirectory(), new 
StandardAnalyzer(), true);
		System.out.println("loaded ram_writer");
		
		Directory[] fs_dir = new Directory[1];
		
		fs_dir[0] = FSDirectory.getDirectory("/tmp/lucene-index/", true);
		System.out.println("loaded fs_dir");
		
		ram_writer.addIndexes(fs_dir);
		System.out.println("load fs_dir into ram");
		
		ram_writer.optimize();
		System.out.println("optimize ram index");
		
		ram_writer.close();
		//index_writer.close();
		
		System.out.println("good");
		}
		catch (IOException ex) {
			System.out.println("io exception");
			
		}	

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Loading FS index into RAM index

Posted by "xing@mac.com" <xi...@mac.com>.
Never mind. I need to read the API more closely. 
RAMDirectory(directory) is built into lucene and already does the trick 
with just one line of code.

xing@mac.com wrote:
> I was reading the Lucene book and came across the part where the author 
> detailed how to write index to ram dir and then flush it to file dir.
> 
> That turned on a light bulb and I want to do bidirectional index 
> loading. Build index in ram, store in file for backup. Then if I have to 
> shutdown the process, I can then ask it to reload the index from file 
> back into ram for searching duties.
> 
> Unforunately my code below which tries to load fs index into ram fails 
> right at "ram_writer.addIndexes(fs_dir);" with io exception. When I 
> check "/tmp/lucene-index/", which contains a proper index,  after the io 
> exception everything was erased and the directory was empty.
> 
> Thanks for any pointers.
> 
> Xing
> 
> 
> try {
>         System.out.println("start");
>         //IndexWriter file_writer = new 
> IndexWriter("/tmp/lucene-index/", new StandardAnalyzer(), true);
>         IndexWriter ram_writer = new IndexWriter(new RAMDirectory(), new 
> StandardAnalyzer(), true);
>         System.out.println("loaded ram_writer");
>        
>         Directory[] fs_dir = new Directory[1];
>        
>         fs_dir[0] = FSDirectory.getDirectory("/tmp/lucene-index/", true);
>         System.out.println("loaded fs_dir");
>        
>         ram_writer.addIndexes(fs_dir);
>         System.out.println("load fs_dir into ram");
>        
>         ram_writer.optimize();
>         System.out.println("optimize ram index");
>        
>         ram_writer.close();
>         //index_writer.close();
>        
>         System.out.println("good");
>         }
>         catch (IOException ex) {
>             System.out.println("io exception");
>            
>         }   
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org