Created
April 4, 2012 21:20
-
-
Save ronnieoverby/2305762 to your computer and use it in GitHub Desktop.
my attempt at ravendb dynamic 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 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