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

Cie*_*iel 6 ravendb

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

{
    Id: "object/id",
    Items: [
        { Id: "1", Name: "One"      },
        { Id: "2", Name: "Two"      },
        { Id: "3", Name: "Three"    }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我可以使用Lucene轻松查询内置的乌鸦动态索引索引;

物品,名称:"一个"

这看起来干净又高效,对于我需要做的一些事情来说是完美的,但是我试图在我自己的索引中重现这种行为,并且非常糟糕.我告诉它索引该领域,但它仍然拒绝让我打电话给它;

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

但这不是我想要做的,我试图将其设置为使用lucene进行查询,就像动态索引一样.这是不是可以做到这一点?

小智 1

是的,这是可以做到的。然而,这并不是一件小事。我建议你看一下文档。我现在正在打电话,但如果您有任何问题,我明天可以给您举个例子。同时你可以看看这个SO答案