2010-03-08 60 views
0

我想在我的C#應用​​程序中實現Lucene.net。 在這一點上,我還處於起步階段:創建一個索引。Lucene.net在IndexWriter創建過程中讀取過去的EOF錯誤

我使用下面的代碼:

var directory = new Lucene.Net.Store.SimpleFSDirectory(new System.IO.DirectoryInfo("d:\\tmp\\lucene-index\\")); 

var analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29); 

var writer = new Lucene.Net.Index.IndexWriter(directory, analyzer, true, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); 

我對作家起始線得到一個IOException異常。 錯誤消息是「Read EOF」,它發生在ReadInt()方法的IndexInput類中。

該代碼確實會在lucene-index目錄(segments.gen和write.lock)中生成一些文件,但都是0字節。 我試圖谷歌這個問題,但我找不到任何有關它的好信息。

有沒有可以幫助我的Lucene.Net專家?

回答

0

以下是我以前使用過的一些代碼。我認爲您遇到的問題是SimpleFSDirectory

var writer = new IndexWriter("SomePath", new StandardAnalyzer()); 
writer.SetMaxBufferedDocs(100); 
writer.SetRAMBufferSizeMB(256); 

// add your document here 
writer.AddDocument(...); 

writer.Flush(); 

// the Optimize method is optional and is used by lucene to combine multiple index files 
writer.Optimize(); 
writer.Close();