C# Lucene.NET中的文档包装器不工作

C# Lucene.NET中的文档包装器不工作,c#,lucene,C#,Lucene,我正在使用Lucene,并为我的文档创建了一个由Lucene索引的包装器类。此包装类内部包含Lucene.Net.Documents.Document的一个实例。看起来是这样的: public class Wrapper { public Document Document { get; private set; } public Wrapper() { this.Document = new Document(); // Addin

我正在使用Lucene,并为我的文档创建了一个由Lucene索引的包装器类。此包装类内部包含Lucene.Net.Documents.Document的一个实例。看起来是这样的:

public class Wrapper
{
    public Document Document { get; private set; }

    public Wrapper()
    {
        this.Document  = new Document();

        // Adding fields here...
        Document.Add(new Field("ID", "", Field.Store.YES, Field.Index.ANALYZED));
        ...
    }

    /// <summary>
    ///     Gets or sets the ID.
    /// </summary>
    public string ID
    {
        get { return this.Document.GetField("ID").StringValue; }
        set { this.Document.GetField("ID").SetValue(value); }
    }

    ...
}
我的问题是索引记录是完全空的。然而,当我调试应用程序并检查包装器实例的variable Document属性时,我可以找到所有值。但它们不存储在索引中

有什么想法吗

到目前为止,我的进一步发现:

相比之下,我发现不使用包装器。。。就像下面。。。工作正常吗

var d = new Document();
d.Add(new Field("ID", "5", Field.Store.YES, Field.Index.ANALYZED));

var writer = new IndexWriter(...);
writer.Add(d);
我发现这个问题+答案:他正在做类似的事情。但我的问题在哪里?问题解决了

我在示例中使用了

writer.Add(document);
…而不是

writer.AddDocument(document);
:/


包装纸很好用。我是通过与Femtorgon的例子进行比较发现的。

我觉得没问题。我尝试使用包装器类编制索引,并且能够搜索文档并从结果文档中检索ID值。也许您发布的代码不足以重现问题?您没有发布完整的代码,因此:您是否将更改提交到索引并随后打开了阅读器?你用过近实时阅读器吗?如果您对这两个问题都回答了“否”,那就是您的问题。提交更改是,但不关闭IndexWriter。之后打开IndexSearcher是。近实时阅读器号。
writer.AddDocument(document);