简体   繁体   English

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

[英]Lucene.net Error: read past EOF on indexWriter.Optimize function

We use lucene.net version 2.0 dll for search in documents. 我们使用lucene.net 2.0版dll在文档中进行搜索。 once we publish the document, content of document is passed to lucene for indexing purpose. 一旦我们发布了文档,文档的内容就会传递给lucene进行索引。 Everything was working fine. 一切都很好。 But now when we publish another document, it throws an error below: 但是现在当我们发布另一个文档时,它在下面引发了一个错误:

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

The problem is we cannot delete files created by lucene, because there are thousands of documents that need to be published again in order to recreate index. 问题在于我们无法删除由Lucene创建的文件,因为有成千上万的文档需要重新发布以重新创建索引。 please suggest solution and/or possible reason why we are getting this error?? 请提出解决方案和/或我们为什么会收到此错误的可能原因??

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

We are using Lucene.net 2.0 as well and have encountered an exception similar to your exception (see below). 我们也正在使用Lucene.net 2.0,并且遇到了与您的异常类似的异常(请参见下文)。 I resolved the issue by deleting the Lucene index directory, and rebuilded the directory again. 我通过删除Lucene索引目录解决了该问题,然后再次重建了目录。

Our Error: 我们的错误:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM