Help with some search logic

Hoping someone can help out with some search stuff…

In my app I have the concept of ‘Cards’ which groups of users can interact with. Two of the things they can do are:

  • ‘Upvote’, which simply increments a ‘counter’ value held against the ‘Card’
  • Add ‘Labels’, which are a type of their own - the ‘Card’ record has a list field which collects which Labels have been applied to it.

My issue is that I’m trying to produce a graph which shows what the most ‘popular’/important labels are, based on how many Upvotes are recorded on Cards where the Label is present.

The X axis seems easy enough (although I’m not sure about how to sort it - more on that in a bit):
Search for Cards:each items selectedLabels:unique elements

This gives me the overall list of unique labels that have been applied to the cards.

Where I’m really struggling is with getting the count of upvotes applied to the Cards on which each Label was present.

So in a Scenario like this:

Card 1
Upvotes: 5
Selected Labels:

  • Label A
  • Label B
  • Label C

Card 2
Upvotes: 3
Selected Labels:

  • Label C

Card 3
Upvotes: 1
Selected Labels:

  • Label B

With my two searches I’d like to end up with something like:

  • ’Label C’, ‘Label B’, ‘Label A’ as the result of my search for the labels to display on the X axis
  • 8, 6, 5 as the result of counting the total ‘Card’ upvotes relating to each label (Logic: The first value relates to Label C, which would be a value of 8 as it was present on Card 1 which received 5 upvotes and on Card 2 which received 3, Label B would be 6 thanks to being on card 1 (5 upvotes) and Card 3 (1 upvote), and Label A was only present on Card 1, so gets a score of 5)

Note the sort order of the first search result would need to match the descending order of the count as calculated in the second search…

Is this possible using the Search feature? I’ve been trying to get my head around how to do the distinct search, plus the ‘summing’ part, all while getting it into the right order… but I’m basically running out of ideas. Any help greatly appreciated :slight_smile:

This topic was automatically closed after 70 days. New replies are no longer allowed.