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

本文关键字:过去 EOF 优化 函数 indexWriter net 错误 读取 Lucene | 更新日期: 2023-09-27 18:21:45

我们使用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();

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

我们也在使用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)