【发布时间】:2012-01-30 16:03:04
【问题描述】:
我正在尝试将来自 here 的 Ayende 订单搜索应用到现有索引。
当前索引如下所示:
public class HomeBlurb_IncludeTotalCosts_Search2 : AbstractIndexCreationTask<MPDocument, HomeBlurb_IncludeTotalCosts_Search2.ReduceResult>
{
public class ReduceResult
{
public string Name { get; set; }
public string Constituency { get; set; }
public decimal? AmountPaid { get; set; }
}
public HomeBlurb_IncludeTotalCosts_Search2()
{
Map = mps => from mp in mps
from exp in mp.Expenses
select new
{
mp.Name,
mp.Constituency,
exp.AmountPaid
};
Reduce = results => from result in results
group result by new { result.Name, result.Constituency } into g
select new
{
Name = g.Key.Name,
Constituency = g.Key.Constituency,
AmountPaid = g.Sum(x => x.AmountPaid)
};
Index(x => x.Name, FieldIndexing.Analyzed);
Index(x => x.Constituency, FieldIndexing.Analyzed);
}
}
这个索引工作正常。但是,当我尝试将地图更改为:
from mp in mps
from exp in mp.Expenses
select new
{
Query = new object[]{mp.Name,mp.Constituency},
mp.Name,
mp.Constituency,
exp.AmountPaid
};
和归约到
from result in results
group result by new { result.Name, result.Constituency } into g
select new
{
Query = "",
Name = g.Key.Name,
Constituency = g.Key.Constituency,
AmountPaid = g.Sum(x => x.AmountPaid)
};
然后,我在查询 Query 属性时没有得到任何结果。如果我删除 reduce 索引返回数据,但它总是返回完整的MPDocument,这比我要实现的要多得多。有没有办法使用原始帖子中描述的技术,也利用了减少?
【问题讨论】:
-
在您的 Reduce 语句中,您将 Query 设置为空字符串,这是正确的吗?如果是这样,唯一匹配它的查询是一个空字符串!
-
当你有一个带有 Reduce 部分的索引时,你查询的是 Reduce 部分的输出,而不是 Map 部分
标签: ravendb