1
以堆棧溢出標記系統爲標準示例,如何取回標記對象的計數?如何根據RavenDB中的索引更新文檔?
鑑於這些實體:
// 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
}
而且TagCount指數
// 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索引。也就是說,我們需要從TagCount索引中的Tags集合和TagCount.Count中顯示Tag.Name和Tag.Description。在SQL Server中,這可以通過一個連接來實現,但這顯然是關係的思維方式。實現這個的習慣RavenDB的方式是什麼?
有沒有辦法給標記實體添加一個Count屬性並讓索引自動更新該屬性?