0
votes

I'm trying to implement Lucene.net in my C# application. At this point i'm still at the very start: creating an index.

I use the following code:

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);

I get an IOException on the writer initialization line. The error message is "Read past EOF" and it occurs in the IndexInput class in the ReadInt() method.

The code does produce some files in the lucene-index directory (segments.gen and write.lock) but both are 0 bytes. I tried to google for this problem but i can't find any good info about it.

Is there a Lucene.Net expert here who can help me?

1

1 Answers

0
votes

Here's some code that I've used before. I think the problem that you are experiencing is with the 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();