只是另一个标签云问题

发布于 2024-10-09 03:41:03 字数 1878 浏览 0 评论 0原文

我有一个行为:

public class Act 
{
    public Act()
    {
        this.Tags = new List<Tag>();
    } 

    public string Id {get; set;}

    public string Name { get; set; }

    public IList<Tag> Tags { get; set; }

}

标签只是:

public class Tag
{
    public string Name { get; set; }

    public string LfmUrl { get; set; }
}

我希望能够查询数据库并获取 TagCount 列表,其中显示标签的名称及其出现的次数。

到目前为止,我有这个:

public class Tags_ByTagCloud : AbstractIndexCreationTask
{
    public override IndexDefinition CreateIndexDefinition()
    {
        return new IndexDefinition<Act, TagAndCount>
                   {
                       Map = docs => from doc in docs
                                     from tag in doc.Tags
                                     select new
                                                {
                                                    Name = tag.Name,
                                                    Count = 1
                                                },
                       Reduce = results => from result in results
                                           group result by result.TagName
                                           into g
                                           select new
                                                      {
                                                          Name = g.Key,
                                                          Count = g.Sum(x => x.Count)
                                                      },
                       SortOptions = {{x => x.Count, SortOptions.Int}}
                   }.ToIndexDefinition(DocumentStore.Conventions);
    }
}

很高兴没有输出任何内容。我知道有数千个行为,每个行为至少有几个标签。有什么想法吗?

理想情况下,我想传递一个 act id 列表来查询它。那么,给定一个行为列表,标签是什么以及执行了多少次 各发生?

i have an act:

public class Act 
{
    public Act()
    {
        this.Tags = new List<Tag>();
    } 

    public string Id {get; set;}

    public string Name { get; set; }

    public IList<Tag> Tags { get; set; }

}

Tag is just:

public class Tag
{
    public string Name { get; set; }

    public string LfmUrl { get; set; }
}

I want to be able to query the DB and get a list of TagCount back which shows the name of the tag and the number of times it appears.

So far I have this:

public class Tags_ByTagCloud : AbstractIndexCreationTask
{
    public override IndexDefinition CreateIndexDefinition()
    {
        return new IndexDefinition<Act, TagAndCount>
                   {
                       Map = docs => from doc in docs
                                     from tag in doc.Tags
                                     select new
                                                {
                                                    Name = tag.Name,
                                                    Count = 1
                                                },
                       Reduce = results => from result in results
                                           group result by result.TagName
                                           into g
                                           select new
                                                      {
                                                          Name = g.Key,
                                                          Count = g.Sum(x => x.Count)
                                                      },
                       SortOptions = {{x => x.Count, SortOptions.Int}}
                   }.ToIndexDefinition(DocumentStore.Conventions);
    }
}

Which happily outputs nothing. I know there are thousands of acts each with at least a few tags. Any ideas?

I ideally want to pass in a list of act ids to query this against. So, given a list of acts, what are the tags and how many times does
each occur?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄傲 2024-10-16 03:41:03

只需更改所有 TagName 以匹配 Name 并且它映射得很好

Just had to change all TagName to match Name and it mapped nicely

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文