以堆栈溢出标记系统为示例,我该如何用其计数恢复标签对象?
给定这些实体:
// Represents the data from the TagCount index
public class TagCount
{
public string Tag { get; set; }
public int Count { get; set; }
}
// Represents the data used to populate a tag-wiki
public class Tag
{
public string Tag { get; set; }
public DateTime Created { get; set; }
public string Description { get; set; }
}
public class Question
{
// elided
public List<string> Tags { get; set; }
// elided
}
以及标记索引的以下定义
// Map
from question in docs.Questions
from Tag in question.Tags
select new { Tag, Count = 1 }
// Reduce
from result in results
group result by result.Tag into g
select new
{
Tag = g.Key,
Count = g.Sum(x=>x.Count)
}
在标签页面上(例如https://stackoverflow.com/tags),我们需要显示标签集合和TagCounts索引的组合。也就是说,我们需要显示tag.name和tag.tag.description。从tags Collection和tagcount.count中显示了TagCount索引。在SQL Server中,这将是通过JOIN实现的,但这显然是关系的思维方式。实现这一目标的惯用方法是什么?
有没有办法将计数属性添加到标签实体并使索引自动更新该属性?
您可以通过修补程序进行操作,也称为API中的UpdateByIndex。您可以在这里看到此:http://blog.hibernatingrhinos.com/12705/new-option-in-the-the-ravendb-studiondash-patching