一連のDomainModelsからの情報を照合するために、インデックス用のRavenDBMapReduce関数を作成しようとしています。すべての結果フィールドに入力することはできませんが、1日ほどを費やしていて、基本的なものが欠けています。
ここにあります:
public class All_Groups : AbstractMultiMapIndexCreationTask<All_Groups.Result>
{
public class Result
{
public string Type { get; set; }
public string Id { get; set; }
public string ChildId { get; set; }
public string Name { get; set; }
public string GroupType { get; set; }
public int MemberCount { get; set; }
public int ProjectCount { get; set; }
public int TeamCount { get; set; }
public int OrganisationCount { get; set; }
public int ChildGroupCount { get; set; }
public AppRoot AppRoot { get; set; }
public Organisation Organisation { get; set; }
public Team Team { get; set; }
public Project Project { get; set; }
public UserProject UserProject { get; set; }
}
public All_Groups()
{
AddMap<AppRoot>(appRoots => from appRoot in appRoots
select new
{
Type = "group",
appRoot.Id,
ChildId = (string)null,
appRoot.Name,
GroupType = "approot",
MemberCount = 0,
ProjectCount = 0,
TeamCount = 0,
OrganisationCount = 0,
ChildGroupCount = 0
});
AddMap<Organisation>(organisations => from organisation in organisations
select new
{
Type = "group",
organisation.Id,
ChildId = (string)null,
organisation.Name,
GroupType = "organisation",
MemberCount = 0,
ProjectCount = 0,
TeamCount = 0,
OrganisationCount = 1,
ChildGroupCount = 0
});
AddMap<Team>(teams => from team in teams
select new
{
Type = "group",
team.Id,
ChildId = (string)null,
team.Name,
GroupType = "team",
MemberCount = 0,
ProjectCount = 0,
TeamCount = 1,
OrganisationCount = 0,
ChildGroupCount = 0
});
AddMap<Project>(projects => from project in projects
select new
{
Type = "group",
project.Id,
ChildId = (string)null,
project.Name,
GroupType = "project",
MemberCount = 0,
ProjectCount = 1,
TeamCount = 0,
OrganisationCount = 0,
ChildGroupCount = 0
});
AddMap<UserProject>(userProjects => from userProject in userProjects
select new
{
Type = "group",
userProject.Id,
ChildId = (string)null,
userProject.Name,
GroupType = "userproject",
MemberCount = 0,
ProjectCount = 0,
TeamCount = 0,
OrganisationCount = 0,
ChildGroupCount = 0
});
AddMap<GroupAssociation>(groupAssociations => from groupAssociation in groupAssociations
select new
{
Type = "groupassociation",
Id = groupAssociation.ParentGroupId,
ChildId = groupAssociation.ChildGroupId,
Name = "n/a",
GroupType = "groupassociation",
MemberCount = 0,
ProjectCount = 0,
TeamCount = 0,
OrganisationCount = 0,
ChildGroupCount = 1
});
AddMap<Member>(members => from member in members
select new
{
Type = "member",
member.Id,
ChildId = (string)null,
Name = "n/a",
GroupType = "member",
MemberCount = 1,
ProjectCount = 0,
TeamCount = 0,
OrganisationCount = 0,
ChildGroupCount = 0
});
Reduce = results => from result in results
group result by result.Id
into g
select new
{
g.Where(x => x.Id == g.Key).First().Type,
Id = g.Key,
g.Where(x => x.Id == g.Key).First().ChildId,
g.Where(x => x.Id == g.Key).First().Name,
g.Where(x => x.Id == g.Key).First().GroupType,
MemberCount = g.Where(x => x.Id == g.Key && x.Type == "member").Sum(x => x.MemberCount),
ProjectCount = g.Where(x => x.GroupType == "project").Sum(x => x.ProjectCount),
TeamCount = g.Where(x => x.GroupType == "team").Sum(x => x.TeamCount),
OrganisationCount = g.Where(x => x.GroupType == "organisation").Sum(x => x.OrganisationCount),
ChildGroupCount = g.Where(x => x.GroupType == "groupassociation" && x.Id == g.Key).Sum(x => x.ChildGroupCount)
};
TransformResults = (database, results) =>
from result in results
let appRoot = database.Load<AppRoot>(result.Id)
let organisation = database.Load<Organisation>(result.Id)
let team = database.Load<Team>(result.Id)
let project = database.Load<Project>(result.Id)
let userProject = database.Load<UserProject>(result.Id)
select new
{
result.Id,
result.Type,
result.Name,
result.GroupType,
AppRoot = appRoot,
Organisation = organisation,
Team = team,
Project = project,
UserProject = userProject,
result.MemberCount,
result.ProjectCount,
result.TeamCount,
result.OrganisationCount,
result.ChildGroupCount
};
Store(x => x.Type, FieldStorage.Yes);
Store(x => x.Id, FieldStorage.Yes);
Store(x => x.Name, FieldStorage.Yes);
Store(x => x.GroupType, FieldStorage.Yes);
Store(x => x.MemberCount, FieldStorage.Yes);
Store(x => x.ProjectCount, FieldStorage.Yes);
Store(x => x.TeamCount, FieldStorage.Yes);
Store(x => x.OrganisationCount, FieldStorage.Yes);
Store(x => x.ChildGroupCount, FieldStorage.Yes);
}
}
基本的に問題は、OrganisationCountとTeamCountのドキュメントは存在しますが、それらの結果が得られないことです。
(ドメインモデル図が必要な場合は、https ://github.com/Bowerbird/bowerbird-web/blob/master/Docs/Model.vsdにあります)
私はこれで髪を引き裂いていて、それはほとんどそこにありますが、私は誰か新鮮な目を必要としますか?
乾杯、
ハミッシュ。