跨多个嵌套属性的 ravendb 索引



我问如何根据文档上的两个不同的嵌套属性创建索引。我正在通过 C# 执行这些查询。

public class LocationCode
{
    public string Code {get;set;}
    public string SeqId {get;set;}
}
public class ColorCode
{
    public string Code {get;set;}
    public string SeqId {get;set;}
}
public class TestDocument
{
    public int Id {get;set;}
    public List<LocationCode> Locations { get; set; }
    public List<ColorCode> Colors { get; set; }
}

我已经尝试了各种AbstractIndexCreationTask,Map和Map+Reduce,但无济于事。

我希望能够执行以下查询:

获取任何 Locations.Code 属性为"USA"和/或 Colors.Code="RED" 或 SeqId 属性的所有文档。我不知道这是否意味着我需要多个索引。通常,我会比较两个嵌套类或 Seq 上的 Code 属性,但从不混合。

请有人指出我正确的方向。

非常感谢菲尔

像这样创建索引:

public class TestIndex : AbstractIndexCreationTask<TestDocument, TestIndex.IndexEntry>
{
    public class IndexEntry
    {
        public IList<string> LocationCodes { get; set; }
        public IList<string> ColorCodes { get; set; }
    }
    public TestIndex()
    {
        Map = testDocs =>
            from testDoc in testDocs
            select new
            {
                LocationCodes = testDoc.Locations.Select(x=> x.Code),
                ColorCodes = testDoc.Colors.Select(x=> x.Code)
            };
    }
}

然后像这样查询它:

var q = session.Query<TestIndex.IndexEntry, TestIndex>()
    .Where(x => x.LocationCodes.Any(y => y == "USA") &&
                x.ColorCodes.Any(y => y == "RED"))
    .OfType<TestDocument>();

完整的单元测试在这里。

最新更新