Skip to content

Instantly share code, notes, and snippets.

@ayende
Created November 21, 2015 14:14
Show Gist options
  • Save ayende/ff4bd34fa3fbf89716d2 to your computer and use it in GitHub Desktop.
Save ayende/ff4bd34fa3fbf89716d2 to your computer and use it in GitHub Desktop.
using System.Linq;
using Orders;
using Raven.Abstractions.Indexing;
using Raven.Client.Indexes;
namespace RavenDB.Course.Nov2015
{
public class Users_Search :
AbstractIndexCreationTask<User, Users_Search.Result>
{
public class Result
{
public string Query;
}
public Users_Search()
{
Map = users =>
from user in users
select new
{
Query = new object[]
{
user.Name,
user.Kids.Select(x=>x.Name)
}
};
Index(x => x.Query, FieldIndexing.Analyzed);
Suggestion(x => x.Query);
}
}
public class Orders_Transformer : AbstractTransformerCreationTask<Order>
{
public class Result
{
public string CompanyName { get; set; }
public decimal Total { get; set; }
public string Id { get; set; }
}
public Orders_Transformer()
{
TransformResults = orders =>
from o in orders
select new Result
{
CompanyName = LoadDocument<Company>(o.Company).Name,
Total = o.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount)),
Id = o.Id
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment