I have a slightly complex index that I need over a Raven db document
given this document definition like:
public class PriceDocument
{
public Guid PriceId { get; set; }
public decimal AskPrice { get; set; }
public decimal BidPrice { get; set; }
public DateTime PricingDate { get; set; }
public string Source { get; set; }
public int Version { get; set; }
public string Id { get; set; }
}
need to get all the products for a given productId( I can do that when I query) that are unique by PricingDate and Source (need to select the latest Version)
so given the following dataset
var priceDocument = new PriceDocument { Price = 1m, Id = productId + "/1", PricingDate = new DateTime(2011, 4, 1, 8,0,0), PriceId = productId, Source = "Bloomberg", Version = 1 };
var priceDocument1 = new PriceDocument { Price = 1m, Id = productId + "/2", PricingDate = new DateTime(2011, 4, 1,9,0,0), PriceId= productId, Source = "Bloomberg", Version = 2 };
I should get as a result priceDocument1 , since its latest
So far I have an index defined like this:
public PriceDocuments_ByDateBySource()
{
Map = docs => from priceDocument in docs
select new { PricingDate = priceDocument.PricingDate, PricingSource = priceDocument.Source, PriceId = priceDocument.PriceId, ProductVersion = priceDocument.Version };
Reduce = results => from result in results
group result by
new
{
result.PricingDate,
result.Source,
result.Version
}
into price
select new
{
PricingDate = price.Key.PricingDate,
PricingSource = price.Key.Source,
ProductVersion = price.Max(p=> price.Key.Version)
};
}
This however returns no errors but also no results
What am I missing ?
Thanks
select new
{
PriceId = null,
PricingDate = price.Key.PricingDate,
PricingSource = price.Key.Source,
ProductVersion = price.Max(p=> price.Key.Version)
};
select new
{
PriceId = price.Select(x=> x.PriceId),PricingDate = price.Key.PricingDate,
PricingSource = price.Key.Source,
ProductVersion = price.Max(p=> price.Key.Version)
};