我可以使用索引作为RavenDB中索引的来源

时间:2014-09-04 11:31:38

标签: ravendb

我正在尝试在RavenDb中定义一个索引,该索引使用另一个索引的输出作为输入,但我无法使其工作。 我有以下实体&索引定义。

SquadIndex产生我希望它做的结果,但SquadSizeIndex似乎甚至没有执行。

我做错了还是不支持?

class Country
{
    public string Id { get; private set; }
    public string Name { get; set; }
}

class Player
{
    public string Id { get; private set; }
    public string Name { get; set; }
    public string CountryId { get; set; }
}

class Reference
{
    public string Id { get; set; }
    public string Name { get; set; }
}

class SquadIndex : AbstractIndexCreationTask<Player, SquadIndex.Result>
{
    public SquadIndex()
    {
        Map = players => from player in players
                         let country = LoadDocument<Country>(player.CountryId)
                         select new Result
                         {
                             Country = new Reference
                             {
                                 Id = country.Id,
                                 Name = country.Name
                             },
                             Players = new[]
    {
        new Reference
        {
            Id = player.Id,
            Name = player.Name

        }
    }
                         };

        Reduce = results => from result in results
                            group result by result.Country
                                into g
                                select new Result
                                {
                                    Country = g.Key,
                                    Players = g.SelectMany(x => x.Players)
                                };
    }

    internal class Result
    {
        public Reference Country { get; set; }
        public IEnumerable<Reference> Players { get; set; }
    }
}

class SquadSizeIndex : AbstractIndexCreationTask<SquadIndex.Result, SquadSizeIndex.Result>
{
    public SquadSizeIndex()
    {
        Map = squads => from squad in squads
                        select new Result
                        {
                            Country = squad.Country,
                            PlayerCount = squad.Players.Count()
                        };

        Reduce = results => from result in results
                            group result by result.Country
                                into g
                                select new Result
                                {
                                    Country = g.Key,
                                    PlayerCount = g.Sum(x => x.PlayerCount)
                                };
    }

    internal class Result
    {
        public Reference Country { get; set; }
        public int PlayerCount { get; set; }
    }
}

1 个答案:

答案 0 :(得分:0)

不,你不能。索引的输出不是要编制索引的文档。 您可以使用脚本化索引结果来链接索引,但这并非易事。