RavenDB - 为正确的集合 LuceneQuery 设置索引

RavenDB - setting up an index for proper collection LuceneQuery

我有一个带有集合的实体,我想为它编制索引,但我很难弄清楚如何去做。问题是我希望使用 Lucene 以与动态索引相同的方式搜索它。不过,这不是一个复杂的对象。一个简单的例子;

{
    Id: "object/id",
    Items: [
        { Id: "1", Name: "One"      },
        { Id: "2", Name: "Two"      },
        { Id: "3", Name: "Three"    }
    ]
}

而且我可以使用 Lucene;

轻松查询 内置的 raven 动态索引 索引

Items,Name: "One"

这看起来简洁高效,非常适合我需要做的一些事情,但我试图在我自己的索引中重现该行为,但失败得很惨。我告诉它索引该字段,但它仍然拒绝让我通过它调用;

public class Things_ByItemProperties : AbstractIndexCreationTask<Thing>
{
    public Things_ByItemProperties()
    {
        Map = things => from thing in things
                    select new
                    {
                        Id = thing.Id,
                        Items = thing.Items
                    };

        Index(n => n.Items, FieldIndexing.Analyzed);
    }
}

我知道我可以将集合的特定部分添加到索引中,像这样;

public class Things_ByItemProperties : AbstractIndexCreationTask<Thing>
{
    public Things_ByItemProperties()
    {
        Map = things => from thing in things
                    select new
                    {
                        Id = thing.Id,
                        Items = thing.Items,
                        Items_Name = this.Select( r => r.Name)
                    };

        Index(n => n.Items, FieldIndexing.Analyzed);
    }
}

但这不是我想要做的,我试图将其设置为使用 lucene 查询它,就像动态索引一样。难道就没有办法做到这一点吗?

是的,可以做到。然而,这并非微不足道。我建议你看看 documentation. I am on the phone right now but if you have some problems with it I can give you an example tomorrow. In the meanwhile you can take a look at this .