Lucene.net错误:在indexWriter.Optimize函数上读取过去的EOF

时间:2013-07-10 14:00:15

标签: c#

我们使用lucene.net版本2.0 dll进行文档搜索。一旦我们发布文档,文档的内容就会被传递给lucene以用于索引目的。一切都很好。但是现在当我们发布另一个文档时,它会抛出一个错误:

System.IO.IOException: read past EOF
at Lucene.Net.Store.BufferedIndexInput.Refill()
at Lucene.Net.Store.BufferedIndexInput.ReadByte()
at Lucene.Net.Store.IndexInput.ReadInt()
at Lucene.Net.Index.IndexWriter.ReadDeleteableFiles()
at Lucene.Net.Index.IndexWriter.DeleteSegments(ArrayList segments)
at Lucene.Net.Index.IndexWriter.MergeSegments(Int32 minSegment, Int32 end)
at Lucene.Net.Index.IndexWriter.FlushRamSegments()
at Lucene.Net.Index.IndexWriter.Optimize()

问题是我们无法删除lucene创建的文件,因为有数千个文档需要再次发布才能重新创建索引。请提出解决方案和/或我们收到此错误的可能原因??

Analyzer analyzer = new StandardAnalyzer();
Lucene.Net.Store.Directory directory = FSDirectory.GetDirectory(lucenePath, false);

try
{
    IndexReader ir = IndexReader.Open(lucenePath);
    ir.DeleteDocuments(new Term("id", document.Lang + "-" + document.IDDoc));
    ir.Close();
}
catch (Exception) { }

IndexWriter iwriter;
try
{
    iwriter = new IndexWriter(directory, analyzer, false);
}
catch (Exception)
{
    iwriter = new IndexWriter(directory, analyzer, true);
}
iwriter.SetMaxFieldLength(25000);
Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
doc.Add(new Lucene.Net.Documents.Field("content", fulltext, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED));
doc.Add(new Lucene.Net.Documents.Field("title", document.DocName, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED));
doc.Add(new Lucene.Net.Documents.Field("id", document.Lang + "-" + document.IDDoc, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.UN_TOKENIZED));
iwriter.AddDocument(doc);
iwriter.Optimize();
iwriter.Close();
directory.Close();

1 个答案:

答案 0 :(得分:0)

我们也在使用Lucene.net 2.0,并遇到了类似于您的异常的异常(见下文)。我通过删除Lucene索引目录解决了该问题,并再次重新编译了该目录。

我们的错误:

System.IO.IOException: read past EOF
   at Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean create, Boolean closeDir, IndexDeletionPolicy deletionPolicy, Boolean autoCommit, Int32 maxFieldLength, IndexingChain indexingChain, IndexCommit commit)
   at Lucene.Net.Index.IndexWriter..ctor(Directory d, Analyzer a, Boolean create, MaxFieldLength mfl)