我正在尝试根据此答案中讨论的最新发布时间来提升文档。
以下索引定义可以很好地创建一个填充了文章和食谱实体的索引。
public class TestIndex : AbstractMultiMapIndexCreationTask<Result>
{
public TestIndex()
{
AddMap<Article>(docs => from doc in docs
where !doc.IsDeleted
select new Result
{
Id = doc.Id,
Title = doc.Title,
DatePublished = doc.DatePublished
}.Boost(doc.DatePublished.Ticks / 1000000f));
AddMap<Recipe>(docs => from doc in docs
where !doc.IsDeleted
select new Result
{
Id = doc.Id,
Title = doc.Title,
DatePublished = doc.DatePublished
}.Boost(doc.DatePublished.Ticks / 100000f));
}
public override string IndexName
{
get { return "Tests/WithBoost"; }
}
}
当我尝试添加 Reduce 以将文档存储为Result
项目时,索引停止生成任何结果。
public class TestIndex : AbstractMultiMapIndexCreationTask<Result>
{
public TestIndex()
{
AddMap<Article>(docs => from doc in docs
where !doc.IsDeleted
select new Result
{
Id = doc.Id,
Title = doc.Title,
DatePublished = doc.DatePublished
}.Boost(doc.DatePublished.Ticks / 100000f));
AddMap<Recipe>(docs => from doc in docs
where !doc.IsDeleted
select new Result
{
Id = doc.Id,
Title = doc.Title,
DatePublished = doc.DatePublished
}.Boost(doc.DatePublished.Ticks / 100000f));
Reduce = docs => from doc in docs
group doc by doc.Id into g
select new Result
{
Id = g.First().Id,
Title = g.First().Title,
DatePublished = g.First().DatePublished
};
}
public override string IndexName
{
get { return "Tests/WithBoost"; }
}
}
使用 Reduce 功能时是否支持提升文档AbstractMultiMapIndexCreationTask<T>
?
我的一个想法是Boost()
返回 a BoostedValue
,所以实际上是传递给 Reduce 表达式的集合IEnumerable<BoostedValue>
而不是IEnumerable<Result>
,因此不能针对输入编译 Reduce 表达式?