Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RavenDB Map Reduce Distinct Index

We have an object with nested properties which we want to make easily searchable. This has been simple enough to achieve but we also want to aggregate information based on multiple fields. In terms of the domain we have multiple deals which have the same details with the exception of the seller. We need consolidate these as a single result and show seller options on the following page. However, we still need to be able to filter based on the seller on the initial page.

We attempted something like the below, to try to collect multiple sellers on a row but it contains duplicates and the creation of the index takes forever.

Map = deals => deals.Select(deal => new
{
    Id = deal.ProductId,
    deal.ContractLength,
    Provider = deal.Provider.Id,
    Amount = deal.Amount
});

Reduce = deals => deals.GroupBy(result => new
{
    result.ProductId,
    result.ContractLength,
    result.Amount
}).Select(result => new
{
    result.Key.ProductId,
    result.Key.ContractLength,
    Provider = result.Select(x => x.Provider).Distinct(),
    result.Key.Amount
});

I'm not sure this the best way to handle this problem but fairly new to Raven and struggling for ideas. If we keep the index simple and group on the client side then we can't keep paging consistent.

Any ideas?

like image 849
Alex Jones Avatar asked Dec 10 '15 17:12

Alex Jones


1 Answers

You are grouping on the document id. deal.Id, so you'll never actually generate a reduction across multiple documents. I don't think that this is intended.

like image 82
Ayende Rahien Avatar answered Nov 03 '22 11:11

Ayende Rahien