Note that there are some explanatory texts on larger screens.

plurals
  1. POInstance counts from list of text tags
    primarykey
    data
    text
    <p>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</p> <pre><code>public class TagItem { public string Id { get; set; } public string UserId { get; set; } public List&lt;string&gt; Tags { get; set;} public DateTime DateCreated { get; set; } } } </code></pre> <p>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 </p> <pre><code>Bacon : 12 Fudge : 8 Marshmallow : 6 </code></pre> <p>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.</p> <p>-- EDIT #1 --</p> <p><strong>Matt</strong></p> <p>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</p> <pre><code> public class Tag_Facets : AbstractIndexCreationTask&lt;UserModel&gt; { public Tag_Facets() { Map = locations =&gt; from user in users from tag in user.Tags select new { Tag = tag.ToString().ToLower(), user.Id }; } } </code></pre> <p>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?</p> <p>My FacetSetup is as follows</p> <pre><code>this.DocumentSession.Store(new FacetSetup { Id = "facets/TagFacets", Facets = new List&lt;Facet&gt; { new Facet { Name = "Tag" } } }); </code></pre> <p>The query that i am trying to build is </p> <pre><code>var facetResults = this.DocumentSession.Query&lt;LocationModel&gt;("Tag/Facets") .Where(x =&gt; x.Id.Contains(new List&lt;string&gt; { "1", "2", "3" })) .ToFacets("facets/TagFacets"); </code></pre> <p>which will not build because Contains doesn't accept List</p> <p>I was hoping that you might be able to point me in the right direction on how I might accomplish this.</p> <p>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!</p> <p>-- EDIT #2 --</p> <p>This is the SQL expression that I would use to achieve the results that I wanted.</p> <pre><code>SELECT t.Tag, COUNT(*) FROM UserTags t WHERE t.UserID in ('1', '2', '3', '4', '5') GROUP BY t.Tag </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload