Skip to content

Instantly share code, notes, and snippets.

@ronnieoverby
Created April 4, 2012 21:20
Show Gist options
  • Save ronnieoverby/2305762 to your computer and use it in GitHub Desktop.
Save ronnieoverby/2305762 to your computer and use it in GitHub Desktop.
my attempt at ravendb dynamic index
public class DynamicIndex : AbstractMultiMapIndexCreationTask<DynamicIndex.ReduceResult>
{
public class ReduceResult
{
public string Value { get; set; }
public int Count { get; set; }
}
public DynamicIndex()
{
IEnumerable<PropertyInfo> propertyInfos = GetThePropertyInfos();
foreach (var property in propertyInfos)
{
AddMap<object>(content => content
.SelectMany(c => (IEnumerable<string>)c.GetPropertyValue(property.Name))
.Select(x => new ReduceResult
{
Value = x,
Count = 1
}));
}
Reduce = results => from r in results
group r by r.Value into g
select new ReduceResult
{
Value = g.Key,
Count = g.Sum(x => x.Count)
};
}
private IEnumerable<PropertyInfo> GetThePropertyInfos()
{
// implementation omitted
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment