1

スタックオーバーフローのタグ付けシステムを標準的な例として取り上げると、タグオブジェクトとそのカウントを取得するにはどうすればよいですか?

これらのエンティティが与えられた場合:

// 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)で、TagsコレクションとTagCountsインデックスの組み合わせを表示する必要があります。つまり、TagsコレクションのTag.NameとTag.Description、およびTagCountインデックスのTagCount.Countを表示する必要があります。SQL Serverでは、これは結合によって実現されますが、これは明らかにリレーショナルな考え方です。これを達成するための慣用的なRavenDBの方法は何ですか?

CountプロパティをTagエンティティに追加し、インデックスにそのプロパティを自動的に更新させる方法はありますか?

4

1 に答える 1

2

これは、APIではUpdateByIndexとも呼ばれるパッチを使用して行います。あなたはここでこれを見ることができます:http: //blog.hibernatingrhinos.com/12705/new-option-in-the-ravendb-studiondash-patching

于 2012-10-22T19:15:36.250 に答える