Skip to content

Commit

Permalink
First Map/Reduce yehaaaaa
Browse files Browse the repository at this point in the history
Produced by Enthusiasm Driven Development
  • Loading branch information
danielmarbach committed Oct 2, 2012
1 parent 1387cdf commit 05c82c6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
15 changes: 12 additions & 3 deletions bbv/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace bbv.Controllers
{
public class SearchController : RavenController
using Raven.Client.Linq;

public class SearchController : RavenController
{
public object Magic(string q)
{
Expand Down Expand Up @@ -49,8 +51,7 @@ public object Magic(string q)

public object SearchRevenues(decimal value)
{
var query = Session.Query<Orders_Search.RevenueResult, Orders_Search>()
.Where(x => x.Revenue > value)
var query = Queryable.Where(this.Session.Query<Orders_Search.RevenueResult, Orders_Search>(), x => x.Revenue > value)
.As<Order>();

var results = query
Expand All @@ -71,5 +72,13 @@ public object CreateOrders()
}
return Json("Done");
}

public object StudentsByEmailDomain(string emailDomain)
{
var results = Session.Query<Students_ByEmailDomain.Result, Students_ByEmailDomain>()
.Where(x => x.EmailDomain == emailDomain);

return Json(results);
}
}
}
35 changes: 35 additions & 0 deletions bbv/Infrastructure/Indexes/Students_ByEmailDomain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace bbv.Infrastructure.Indexes
{
using System.Linq;

using Raven.Client.Indexes;

using bbv.Models;

public class Students_ByEmailDomain : AbstractIndexCreationTask<Student, Students_ByEmailDomain.Result>
{
public class Result
{
public string EmailDomain { get; set; }
public int Count { get; set; }
}

public Students_ByEmailDomain()
{
Map = students => from student in students
select new
{
EmailDomain = student.Email.Split('@')[1],
Count = 1
};

Reduce = results => from result in results
group result by result.EmailDomain into g
select new
{
EmailDomain = g.Key,
Count = g.Sum(r => r.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 @@
</Compile>
<Compile Include="Infrastructure\AuditListener.cs" />
<Compile Include="Infrastructure\Indexes\Orders_Search.cs" />
<Compile Include="Infrastructure\Indexes\Students_ByEmailDomain.cs" />
<Compile Include="Infrastructure\Indexes\Students_Search.cs" />
<Compile Include="Models\Course.cs" />
<Compile Include="Models\Order.cs" />
Expand Down

0 comments on commit 05c82c6

Please sign in to comment.