C# で mongoDB からツイートを取得するメソッドを作成し、リツイートの数で著者を数えて並べ替えたいと考えています。
現在、このメソッドはすでに map と reduce を実行しており、次の方法でソートされていない結果を返しています。
public void RetweetsCount()
{
string wordMap = @"function wordMap() {
var usernameOrigin = this.text.match(/\brt\s*@(\w+)/i);
if (usernameOrigin === null) {
return;
}
// loop every word in the document
emit(usernameOrigin[1], { count : 1 });
}";
string wordReduce = @"function wordReduce(key, values) {
var total = 0;
for (var i = 0; i < values.length; i++) {
total += values[i].count;
}
return { count : total };
}";
var options = new MapReduceOptionsBuilder();
options.SetOutput(MapReduceOutput.Inline);
var results = collection.MapReduce(wordMap, wordReduce, options);
foreach (var result in results.GetResults())
{
Console.WriteLine(result.ToJson());
}
}
カウント値 (リツイート数) の降順で結果を並べ替える方法を知っている人はいますか?