多个嵌套属性的ravendb索引

Phi*_*hil 2 c# indexing 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; }
}
Run Code Online (Sandbox Code Playgroud)

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

我希望能够进行如下查询:

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

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

非常感谢Phil

Mat*_*int 6

像这样创建你的索引:

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

然后像这样查询:

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

完整的单元测试.