Sort RG by count of :intersect with matches

I have a datatype Course with the field seach-tags which is a list of texts. The user can type in the search bar to search for any courses that have matching ‘search tags’ as the text they typed.

My RG displays Courses that have search-tags:intersect with the text a user types in the search bar: split by ( ):count > 0

This correctly gives me any courses that match the words in the user’s search query split by a space, with courses that have one or more of those words in their search-tags field. But how can I sort the RG to show the courses with the most matches first and the least matches last?

Thanks for any help, ideas or suggestions

you would use the group by operator to group the results and add an aggregation of count, then in the datasource of the rg, add the operator sort by and choose count (the aggregation from the grouping)

Thanks for the response! Unfortunately the group by operator won’t work on a field that is a list of texts.

I found a video by Keith who created list shifter etc. doing something similar to what i need to do using list shifter/floppy plugin but i don’t think it would work for my case. Perhaps the video will give more context on what i want to achieve though.

Maybe change the field to an option set if you are going to have a list of tags that are predetermined for your courses, or make it a data type of it’s own if you are going to allow users to create new tags.

1 Like

Group by still doesn’t seem like the correct operator here because it can’t count the matches between two separate lists.

Essentially i just want to create a fairly standard “search” feature like youtube or etsy. A user types in whatever they like, and the course with the most matching ‘tags/keywords’ show up first and the least matching down the bottom. When its a single word its easy but with a list of words for some reason I’m really struggling.

Since when are you counting matches between two separate lists? Is ‘the text’ the user types a list of tags or a single value?

Seems like you are giving the user an input, and allowing them to free type whatever they want and you then split the input value into a list of words?

1 Like

The RG’s filter is splitting the text string into a list of texts with the :split by operator. If the user types “beginner spanish” it is splitting the text by the space in the middle and returning the list “beginner” and “spanish.”

This filtering i’ve set up correctly returns all Courses that have tags/keywords matching any of the words (split by a space) that the user types. Now I’d like to sort those courses by the number of words that match.

I’m aware I might be overcomplicating the whole search thing, so if there is another way to allow a search and then sort the results by relevance to the search query, i’m open to anything.

What is the content type in your RG? I see courseLight…is that just text?

CourseLight is a satellite datatype for my “Course” datatype and contains a couple fields like a course image, title etc… I’d like the RG to display the list of CourseLights based on their search. The RG’s datatype is CourseLight.

CourseLight has a field called “keywords” which is a list of ~13 texts that are generally one word each such as “beginner” and “spanish”. This keywords field is the list of texts that is being intersected with the list of texts extracted from the search bar (and saved as a parameter in the url). Sounds a lot more complicated when i type it out haha, sorry if I’m making it difficult to understand.

I’ve actually found a convoluted solution by formatting the datatype as text and regexing and blah blah but i’d really prefer not to do it that way haha. If there are any suggestions i’d really appreciate any advice

Why not? If it works, it works. Sometimes in Bubble, the only way to get something to work the way you need it to, is to do something that may seem convoluted.

Is there a speed issue or does it make it impossible to do some other necessary actions or features? If not, my advice is keep it as you have it, and move onto the next task.

There is no native way of taking an intersect with (ie: return only courses that have in a list of tags a value that matches at least one value from a list of texts from the users input value) and then finding through the dynamic expression the number of matches of tags for each course and then sorting by that value.

1 Like

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