我正在使用Lucene.net并且我正在尝试将Exception读取为EOF而我试图获取术语频率向量,这是我的代码:
public class DocumentData
{
public int Id { get; set; }
public string Title { get; set; }
public string Body { get; set; }
}
public static string CONTENT = "Body";
// Method that adds a new document to the index
public static void AddToLuceneIndex(DocumentData documentData, IndexWriter writer)
{
//remove older index entry
var searchQuery = new TermQuery(new Term("Id", documentData.Id.ToString()));
writer.DeleteDocuments(searchQuery);
//add a new index entry
var doc = new Document();
//add lucene fields mapped to db fields
doc.Add(new Field("Id", documentData.Id.ToString() ?? "", Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.Add(new Field("Title", documentData.Title ?? "", Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field(CONTENT, documentData.Body ?? "", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
//add entry to index
writer.AddDocument(doc);
}
// Gets the term frequency vectors for the ids in docs
private static ITermFreqVector[] GetVectors(int[] docs, FSDirectory directory)
{
var reader = IndexReader.Open(directory, true);
var answer = docs.Select(x => reader.GetTermFreqVector(x, LuceneSearch.CONTENT)).ToArray(); // the exception is thrown at this point
reader.Dispose();
return answer;
}
我向索引添加了一些文档,然后我得到了这些文档的频率向量,一切正常,但是当我再次添加文档并调用GetVectors函数时,抛出了异常。我该如何解决这个问题?