Skip to content

Instantly share code, notes, and snippets.

@ayende

ayende/index.cs Secret

Created December 29, 2024 15:50
Show Gist options
  • Save ayende/bd3e42f1267343ef9549837362b345c3 to your computer and use it in GitHub Desktop.
Save ayende/bd3e42f1267343ef9549837362b345c3 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Linq;
using Raven.Client.Documents.Indexes;
public class Index_MyIndex : AbstractIndexCreationTask
{
public override string IndexName => "MyIndex";
public override IndexDefinition CreateIndexDefinition()
{
return new IndexDefinition
{
Maps =
{
@"map(""WorkPackages"",processWorkBreakdownHours);",
@"map(""Subs"",processWorkBreakdownHours);",
@"map(""Majors"",processWorkBreakdownHours);",
@"map(""Projects"",processWorkBreakdownHours);"
},
Reduce = @"groupBy(x => x.Scope).aggregate(g => {
return {
Scope: g.key,
EsimatedHours: g.values.reduce((count, val) => val.EsimatedHours + count, 0),
CompletedHours: g.values.reduce((amount, val) => val.CompletedHours + amount, 0)
};
})",
AdditionalSources = new Dictionary<string, string>
{
["map.js"] = @"function processWorkBreakdownHours(doc) {
let hours = {
EsimatedHours: doc.EsimatedHours,
CompletedHours: doc.CompletedHours
};
let results = [Object.assign({
Scope: id(doc)
}, hours)];
let current = doc;
while (current.Parent) {
current = load(current.Parent.Id, current.Parent.Type);
results.push(Object.assign({
Scope: id(current)
}, hours));
}
return results;
}"
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment