I\'m looking for an example of how to implement and use Map-Reduce within the RavenDB .NET Client.
I\'d like to apply it to a specific scenario: generating unique a
Here is how you can build an index for unique visitors:
public class Statistics_UniqueVisitors : AbstractIndexCreationTask
{
public Statistics_UniqueVisitors()
{
Map = entries => from entry in entries
select new { entry.UserId, Count = 1 };
Reduce = results => from result in results
group result by result.UserId into g
select new { UserId = g.Key, Count = g.Sum(x=>x.Count) };
}
}
You can then query this using:
var numberOfUniqueVisitors = s.Query().Count();
For total count of visitors, you can use:
var numberOfVisitors = s.Query().Count();