3
我有一個需求,我需要獲取競賽日期排序的競賽列表。但是我也需要把我的朋友們跑過的比賽加到最上面。所以我試圖保持一個索引,以保持我的朋友在每場比賽中都能獲勝。RavenDb - 通過結果篩選組的多映射索引
我有以下對象:
public class Race {
public string Id { get; set; }
public string Name { get; set; }
public string Distance { get; set; }
public DateTime DateOfEvent { get; set; }
public string Location { get; set; }
}
public class Runner {
public string Id { get; set; }
public string Name { get; set; }
public DateTime DateOfBirth { get; set; }
public string Hometown { get; set; }
public List<string> Friends { get; set; }
public List<string> RacesRun { get; set; }
}
這是我迄今該指數:
public class RacesByFriends : AbstractMultiMapIndexCreationTask<RacesByFriends.ReduceResult> {
public class ReduceResult {
public string RunnerId { get; set; }
public string RaceId { get; set; }
public int Count { get; set; }
}
public RacesByFriends() {
AddMap<Runner>(runners => from runner in runners
from race in runner.RacesRun
select new {
RunnerId = runner.Id,
RaceId = race,
Count = 1,
});
AddMap<Race>(races => from race in races
select new {
RunnerId = (string)null,
RaceId = race.Id,
Count = 0,
});
Reduce = results => from result in results
group result by new {
result.RunnerId,
result.RaceId
} into g
select new {
RunnerId = g.Select(x => x.RunnerId).FirstOrDefault(),
RaceId = g.Select(x => x.RaceId).FirstOrDefault(),
Count = g.Sum(x => x.Count)
};
}
}
我的問題是,我該如何得到伯爵在ReduceResult到只反映那些跑步者朋友名單中存在的人。