Created
May 9, 2012 22:56
-
-
Save benfoster/2649514 to your computer and use it in GitHub Desktop.
Raven multi map index
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 Vacancies_SummaryWithApplicationCount : AbstractMultiMapIndexCreationTask<VacancySummary> | |
{ | |
public Vacancies_SummaryWithApplicationCount() | |
{ | |
AddMap<Vacancy>(vacancies => from v in vacancies | |
select new | |
{ | |
Id = v.Id, | |
Position = v.Position, | |
StateId = v.StateId, | |
DateSubmitted = v.DateSubmitted, | |
ApplicationCount = 0 | |
}); | |
AddMap<VacancyApplication>(applications => from a in applications | |
select new | |
{ | |
Id = a.VacancyId, | |
Position = (string)null, | |
StateId = (string)null, | |
DateSubmitted = DateTime.MinValue, | |
ApplicationCount = 1, | |
}); | |
Reduce = results => from result in results | |
group result by result.Id into summary | |
select new | |
{ | |
Id = summary.Key, | |
Position = summary.Select(x => x.Position).Where(x => x != null).FirstOrDefault(), | |
StateId = summary.Select(x => x.StateId).Where(x => x != null).FirstOrDefault(), | |
DateSubmitted = summary.Select(x => x.DateSubmitted).Where(x => x != DateTime.MinValue).FirstOrDefault(), | |
ApplicationCount = summary.Sum(x => x.ApplicationCount) | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment