Calculating the MIN and MAX values in the index will not perform because you would have to calculate for each possible combination of usergroups. But what you can do is map the usergroup price like this and then do a sort on the amountprice either asc or desc depending if you want to have MIN or MAX.
public class ProductUserGroupPrices : AbstractIndexCreationTask<Product, Product>
{
public ProductUserGroupPrices()
{
Map = products => from product in products
from price in product.Prices
select new
{
UserGroupId = price.UserGroupId
PriceAmount = price.PriceAmount,
ProductId = product.Id
};
Sort(x => x.PriceAmount, SortOptions.Double);
Stores.Add(x => x.PriceAmount, FieldStorage.Yes);
}
}
The query to get the MIN price for a product for a list of usergroupids would look something like this. (note that I haven't tested this code)
public class ProductUserGroupPrice
{
public double PriceAmount { get; set; }
}
This query will not get the documents as results, but the values from the index. In this case the priceAmount because we have said in the index definition it should be stored.
var results = session.Advanced.LuceneQuery<Product>("ProductUserGroupPrices")
.SelectFields<ProductUserGroupPrice>()
.WhereEquals(x => x.ProductId, productId)
.AndAlso()
.WhereIn(x => x.UserGroupId, userGroupIds)
.OrderBy(x => x.PriceAmount)
.FirstOrDefault();