Skip to content

Commit

Permalink
Awesome index
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Oct 2, 2012
1 parent 0d920fa commit 8c247fd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bbv/Infrastructure/Indexes/Animals_Stats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Linq;
using Raven.Client.Indexes;
using bbv.Models;

namespace bbv.Infrastructure.Indexes
{
public class Animals_Stats : AbstractIndexCreationTask<Animal, Animals_Stats.ReduceResult>
{
public class ReduceResult
{
public string Species { get; set; }
public int Count { get; set; }
public BreedStats[] Breeds { get; set; }

public class BreedStats
{
public string Breed { get; set; }
public int Count { get; set; }
}
}

public Animals_Stats()
{
Map = animals =>
from animal in animals
select new
{
animal.Species,
Count = 1,
Breeds = new [] {new {animal.Breed, Count = 1}}
};
Reduce = animals =>
from r in animals
group r by r.Species
into g
select new
{
Species = g.Key,
Count = g.Sum(x => x.Count),
Breeds = from breed in g.SelectMany(x => x.Breeds)
group breed by breed.Breed
into gb
select new {Breed = gb.Key, Count = gb.Sum(x => x.Count)}
};

}
}
}
1 change: 1 addition & 0 deletions bbv/bbv.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Infrastructure\AuditListener.cs" />
<Compile Include="Infrastructure\Indexes\Animals_Stats.cs" />
<Compile Include="Infrastructure\Indexes\Orders_Search.cs" />
<Compile Include="Infrastructure\Indexes\Students_ByEmailDomain.cs" />
<Compile Include="Infrastructure\Indexes\Students_Search.cs" />
Expand Down

0 comments on commit 8c247fd

Please sign in to comment.