Sorting lists with logic or formulas

Hey guys.

I’m trying to serve a single thing of custom type “Song” to a user (for them to review) based on the first item of a list of songs, but the list needs to be ordered in a certain logic-based way (surely there’s some way to use AND/OR type logic, but i just can’t figure it out for the life of me!)

Each Song has a field called GenreProfile of custom type GenreProfile (another thing), and the thing GenreProfile has fields for 6 numbers and a Song (ParentSong). A Song also has a field called NoOfReviews which is a number that increases with each review.

Also each user has a field “GenreProfile” with the same type, where their genre preferences are stored (and ParentSong will be blank for those)

I want the list order to be decided partly by taste match, (:RankedBy similarity to Current User’s GenreProfile) but also partly by how low NoOfReviews is. And ideally I want to make this on a sliding scale, where if NoOfReviews is zero, it gets 90% weighting, and when NoOfReviews>10 then theyre ordered by GenreProfile Similarity alone.

And then I only want to return the 1st song in the list.

I can’t figure out how this might be possible, after trying lots of ways for about 2hrs now and reading a bunch of threads on here, but also i’m a noob so maybe i’m overlooking something obvious!

Thanks so much for anyone that can help. I’ve only been using Bubble for about 3 full days now, and am absolutely blown away by it’s power and the endless possibilities of what i hope to do with it! :smiley:

Sounds like a complex sorting, how did you go with it?

Did you find the advanced option on the “:filtered” list operator? I’m thinking that for each ordering criteria, you could filter to show the ones with the higher weighting/ranking, then do another filter/ranking on the result.

Thanks, will try that when i get chance. For now i just simplified what i was trying to do, bit of a cop out but there’s a million other bugs i need to fix now before i get back to this one!

I just used “RankedBy” and “First Item” to get one list and pick the best match from it, then I used a Conditional to override that anytime it gets a result on a search for songs older than 2 days with less than 5 reviews. It broadly accomplishes the same thing, just not as nicely.

I really find it weird that there’s no apparent way to use simple spreadsheet style formulas on the database though. Hopefully that’s something that will be added… I hear there might be a way to connect to a Google Sheet, but that sounds very hacky :confused:

“Calculate formula” looks like it should be the option i’d want, but within that there’s no actual option to enter your own formula by which to calculate. That’s what I hope they add!

At least I realised i can achieve it without AND/OR/IF logic-type statements, just a standard maths formula (took a while to work out the correct weighting to get the results i wanted though)… If anyone knows how i can directly implement this formula to sort the list, that’d be awesome.

"Choose first song in a list ordered (decending) by following formula:
[(NoOfReviews+1) x Similarity%] - [NoOfReviews x 100] + 900 + [AgeInDays x 200 / (AgeInDays+NoOfReviews+3)]
"

(Similarity% would be calculated the same way that “RankedBy” works, which is handily explained on another thread here from a few days ago)