我與RavenDB的多地圖奮力/減少的概念,最近問this question關於如何正確地寫多的map/reduce指數。IList <T>多圖/縮小結果?
我得到了這個問題的工作簡單的指標,但是,當我試圖使它有點複雜,我不能使它發揮作用。我想要做的是有指標的結果包含字符串列表,即:
class RootDocument {
public string Id { get; set; }
public string Foo { get; set; }
public string Bar { get; set; }
public IList<string> Items { get; set; }
}
public class ChildDocument {
public string Id { get; set; }
public string RootId { get; set; }
public int Value { get; set; }
}
class RootsByIdIndex: AbstractMultiMapIndexCreationTask<RootsByIdIndex.Result> {
public class Result {
public string Id { get; set; }
public string Foo { get; set; }
public string Bar { get; set; }
public IList<string> Items { get; set; }
public int Value { get; set; }
}
public RootsByIdIndex() {
AddMap<ChildDocument>(
children => from child in children
select new {
Id = child.RootId,
Foo = (string)null,
Bar = (string)null,
Items = default(IList<string>),
Value = child.Value
});
AddMap<RootDocument>(
roots => from root in roots
select new {
Id = root.Id,
Foo = root.Foo,
Bar = root.Bar,
Items = root.Items,
Value = 0
});
Reduce =
results => from result in results
group result by result.Id into g
select new {
Id = g.Key,
Foo = g.Select(x => x.Foo).Where(x => x != null).FirstOrDefault(),
Bar = g.Select(x => x.Bar).Where(x => x != null).FirstOrDefault(),
Items = g.Select(x => x.Items).Where(
x => x != default(IList<string>).FirstOrDefault(),
Value = g.Sum(x => x.Value)
};
}
}
基本上我想設置的項目屬性爲默認(IList的)映射ChildDocuments和價值時, RootDocument的Items屬性。然而,這不起作用。它提供錯誤消息
錯誤的請求無法理解查詢:
- 2號線山坳285:無效Expr的
- 2號線山坳324:無法解析雙.0.0
上傳索引時。我如何處理多地圖/縮小索引中的列表?
好吧,我只是想我可以索引任何我可以存儲(並存儲IList工作正常)。 –
2011-12-27 05:58:09