Skip to content

Instantly share code, notes, and snippets.

@felipeleusin
Created March 14, 2011 00:41
Show Gist options
  • Save felipeleusin/868603 to your computer and use it in GitHub Desktop.
Save felipeleusin/868603 to your computer and use it in GitHub Desktop.
// This works
public class Users_ContractCharges : AbstractIndexCreationTask
{
public override IndexDefinition CreateIndexDefinition()
{
return new IndexDefinition<User, User>()
{
Map = results => from user in results select new { user.Id },
TransformResults = (database, results) => from user in results
from charges in user.Contract.Charges
select new
{
charges.Name, charges.Type, charges.Value
}
}
.ToIndexDefinition(DocumentStore.Conventions);
}
}
// This doesnt, but IMO, should work
public class Users_ContractCharges2 : AbstractIndexCreationTask
{
public override IndexDefinition CreateIndexDefinition()
{
return new IndexDefinition<User, User.UserContract.SalaryCharge>()
{
Map = results => from user in results
from charges in user.Contract.Charges
select new
{
charges.Name,
charges.Type,
charges.Value
},
Reduce = results => from charges in results
group charges by new { charges.Name, charges.Type } into g
select new { Name = g.Key.Name, Type = g.Key.Type, Value = g.Max(x => x.Value)},
}
.ToIndexDefinition(DocumentStore.Conventions);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment