希望你能幫助我!複雜的MapReduce查詢與RavenDB
我正在收集tweets,它有一個created_at日期(DataPublicacao)和一些Hashtags。每條推文指廣播者(redeId)和節目(programaId)。 我想在某個時間段內查詢數據庫中20個最常用的主題標籤。
我必須映射每個哈希標籤,當它被使用時,以及它指向哪個廣播公司和電視節目。
然後,我需要能夠計算在某個時期(我不知道如何)每個哈希標籤的發生。
public class Tweet : IModelo
{
public string Id { get; set; }
public string RedeId { get; set; }
public string ProgramaId { get; set; }
public DateTime DataPublicacao { get; set; }
public string Conteudo { get; set; }
public string Aplicacao { get; set; }
public Autor Autor { get; set; }
public Twitter.Monitor.Dominio.Modelo.TweetJson.Geo LocalizacaoGeo { get; set; }
public Twitter.Monitor.Dominio.Modelo.TweetJson.Place Localizacao { get; set; }
public Twitter.Monitor.Dominio.Modelo.TweetJson.Entities Entidades { get; set; }
public string Imagem { get; set; }
public Autor Para_Usuario { get; set; }
public string Retweet_Para_Status_Id { get; set; }
}
而「實體」是主題標籤,用戶名和網址。
我試圖通過廣播公司,電視節目和文本對標籤進行分組,並列出出現的日期。然後,我必須改變結果,所以我可以統計那個時期的事件。
public class EntityResult
{
public string hashtagText { get; set; }
public string progId { get; set; }
public string redeId { get; set; }
public int listCount { get; set; }
}
public class HashtagsIndex : AbstractIndexCreationTask<Tweet, HashtagsIndex.ReduceResults>
{
public class ReduceResults
{
public string hashtagText { get; set; }
public DateTime createdAt { get; set; }
public string progId { get; set; }
public string redeId { get; set; }
public List<DateTime> datesList { get; set; }
}
public HashtagsIndex()
{
Map = tweets => from tweet in tweets
from hts in tweet.Entidades.hashtags
where tweet.Entidades != null
select new
{
createdAt = tweet.DataPublicacao,
progId = tweet.ProgramaId,
redeId = tweet.RedeId,
hashtagText = hts.text,
datesList = new List<DateTime>(new DateTime[] { tweet.DataPublicacao })
};
Reduce = results => from result in results
group result by new { result.progId, result.redeId, result.hashtagText }
into g
select new
{
createdAt = DateTime.MinValue,
progId = g.Key.progId,
redeId = g.Key.redeId,
hashtagText = g.Key.hashtagText,
datesList = g.ToList().Select(t => t.createdAt).ToList()
};
}
}
我迄今所取得的查詢是:
var hashtags2 = session.Query<dynamic, HashtagsIndex>().Customize(t => t.TransformResults((query, results) =>
results.Cast<dynamic>().Select(g =>
{
Expression<Func<DateTime, bool>> exp = o => o >= dtInit && o <= dtEnd;
int count = g.Where(exp);
return new EntityResult
{
redeId = g.redeId,
progId = g.progId,
hashtagText = g.hashtagText,
listCount = count
};
}))).Take(20).ToList();
現在我需要OrderByDescending(T => t.count),所以我不能就這一時期(20)最常用的井號標籤。
我該怎麼做?
請張貼一些代碼來顯示您問的問題。你的問題目前沒有太多意義。 –
嗨馬特。它更清楚嗎?如果沒有,請告訴我,我會編輯我的問題。 –