Created
March 23, 2020 12:01
-
-
Save ayende/52fd8bd7ff84004be489215b7cfe8289 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GetIdeas_Index: AbstractMultiMapIndexCreationTask<GetIdeas_Index.Result> | |
{ | |
public class Result | |
{ | |
public int TenantId { get; set; } | |
public int ApplicationId { get; set; } | |
public Guid IdeaId { get; set; } | |
public string IdeaTitle { get; set; } | |
public string CultureTag { get; set; } | |
public int StateId { get; set; } | |
public string StateTitle { get; set; } | |
} | |
public GetIdeas_Index() | |
{ | |
AddMap<StateIdea>(states => | |
from p in states | |
from state in p.States | |
select new | |
{ | |
p.TenantId, | |
p.ApplicationId, | |
p.CultureTag, | |
state.StateId, | |
StateTitle = state.Title, | |
IdeaTitle = string.Empty | |
}); | |
AddMap<Idea>(ideas => | |
from idea in ideas | |
select new | |
{ | |
idea.TenantId, | |
idea.ApplicationId, | |
CultureTag = string.Empty, | |
idea.StateId, | |
StateTitle = string.Empty, | |
IdeaTitle = idea.Title | |
}); | |
Reduce = results => | |
from r in results | |
group r by r.StateId | |
into g | |
select new | |
{ | |
TenantId = g.Select(p => p.TenantId).FirstOrDefault(), | |
ApplicationId = g.Select(p => p.ApplicationId).FirstOrDefault(), | |
CultureTag = g.Select(p => p.CultureTag).FirstOrDefault(p => p != string.Empty), | |
StateId = g.Key, | |
StateTitle = g.Select(p => p.StateTitle).FirstOrDefault(p => p != string.Empty), | |
IdeaTitle = g.Select(p => p.IdeaTitle).FirstOrDefault(p => p != string.Empty) | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment