2

I'm creating a platform to search products based on certain filters. Let's say I have filters A, B and C and a database of around 20,000 products. What I'm trying to build is a way to create a ranking score and query the list of products based on that score. If a product gets a match with filter A, B and C it has a score of 3, therefore, will be visible first in the list with all products of the same score. Then the products with a score of 2. Then 1 and 0.

I'm using Algolia for now using optional_filters but I was wondering if there was a way to build it with a relational database directly like Supabase. Our app is based on Nextjs + Supabase.

Any idea?

  • So, yes, this is trivial in an RDBMS. You can have arbitrarily many clauses in your `WHERE` condition, and would simply `ORDER BY score DESC` to get the behavior you're asking for. And 20k rows is pretty small. edit: ah, I misunderstood, you want matching A+B+C to be 3, A+B (or A+C or B+C) to be 2, etc. This is also straightforward with an RDBMS: you simply evaluate each filter as a column, and sum them together. – AdamKG Apr 06 '21 at 21:37

0 Answers0