I have a database of consumer products and I need to filter based on their specs. These queries can be filtering upwards of 10 varying types of fields. This often leads to no exact matches. When there are no exact matches, I would like to return the most similar products. I figured the easiest way to do this would be to annotate a "count" for each column that does match a filter. Then order by products with the greatest "count". Is there a way to do this? Or is there some other way to get similar matches with Django?
For example if I have the following query:
Laptop.objects.filter(brand='Dell', ram=8, price__lte=1000, screen_size=13.3)
If the queryset is empty i'd like to return the laptop with the most matching fields of those 4 filters.