Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7790523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:36:41+00:00 2026-06-01T21:36:41+00:00

I am using RavenDB and allowing a user to enter an item into the

  • 0

I am using RavenDB and allowing a user to enter an item into the database with which they can associate textual tags. The class for the item is

public class TagItem
    {
        public string Id { get; set; }
        public string UserId { get; set; }
        public List<string> Tags { get; set;}
        public DateTime DateCreated { get; set; }
    }
}

What i would like to do is get an instance count for each individual tag in a selection of items from the document query. For instance

Bacon : 12
Fudge : 8
Marshmallow : 6

I am currently doing this by iterating through the items and incrementing the count for each tag but it doesn’t seem to be a very elegant way of obtaining the results. I was wondering if anyone had a suggestion for a better way to achieve this? Thanks in advance.

— EDIT #1 —

Matt

I have tried to implement your suggestion of faceted search but I cant seem to figure out how to perform a selection using a subset of userIDs. I have created the index as the following

   public class Tag_Facets : AbstractIndexCreationTask<UserModel>
   {
    public Tag_Facets()
    {
        Map = locations => from user in users 
                           from tag in user.Tags
                           select new { Tag = tag.ToString().ToLower(), user.Id };
    }
   }

I have a List of UserIds that I would like to use to narrow this selection down before running the facet against it but none of the methods that I have tried want to compile. Can you provide me with an idea of what the Where clause would look like for this?

My FacetSetup is as follows

this.DocumentSession.Store(new FacetSetup { Id = "facets/TagFacets", Facets = new 
List<Facet> { new Facet { Name = "Tag" } } });

The query that i am trying to build is

var facetResults = this.DocumentSession.Query<LocationModel>("Tag/Facets")
                .Where(x => x.Id.Contains(new List<string> { "1", "2", "3" }))
                .ToFacets("facets/TagFacets");

which will not build because Contains doesn’t accept List

I was hoping that you might be able to point me in the right direction on how I might accomplish this.

Also, thank you for your work on Faceted Search. It seems to be what I’m looking for to perform a lot of the queries that I need to run in RavenDB. Cheers!

— EDIT #2 —

This is the SQL expression that I would use to achieve the results that I wanted.

SELECT t.Tag, COUNT(*) FROM UserTags t WHERE t.UserID in ('1', '2', '3', '4', '5') GROUP BY t.Tag
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:36:42+00:00Added an answer on June 1, 2026 at 9:36 pm

    Another approach is to use faceted search and get the counts from that. It’s a little bit more flexible than Map/Reduce as it allows you to specify a query when you get the counts.

    Given an index like this:

        from question in docs
        from tag in question.Tags
        select new 
        { 
            question.CreatedOn, 
            Tag = tag
        }
    

    You then define the facet ranges like this (using the default behaviour, which will look for every unique term for you)

        var facetSetupDoc = new FacetSetup 
            { 
                Id = "facets/TagFacets", 
                Facets = new List<Facet> { new Facet {Name = "Tag"} } 
            }
    

    Finally you query it like this:

        var facetResults = s.Query<Question>("QuestionTags")
                    .Where(x => x.CreatedOn >= new DateTime(2008, 5, 20))
                    .ToFacets("facets/TagFacets");
    

    Take a look at this code sample, it shows how to implement your exact scenario.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started using RavenDB today. When I save a class, I can see the
I'm using RavenDB & need to store dynamic data like: public class User {
I am using the embedded version of RavenDb and have put the physical database
Im having Trouble setting up an in memory database using RavenDB. The error I
Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
I'm using RavenDB build 371 and I have the following model: class Product {
In RavenDB, I would like to query the database using a date field. How
I have integration tests using RavenDB with RunInMemory = true . One of the
We're using RavenDB saga storage, but the saga data isn't being persisted after the
I am new to using RavenDB and trying to get indexes to work in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.