I will break this into two parts:
I have a user with a list of product 'features' that he desires. The user is asked to rank these features from 1-10. I also have a table full of products. Each of these products has various features. Some products will have all features 1-10, but some will only have a few of them. I'd like to determine which product matches the user's ranking the best, and provide an ordered result set to the user, with the best match first and the worst match last.
The aforementioned query is actually just one part of what the user is doing. The user is also providing other search criteria (e.g. product category, price, etc) along with the feature ranking. So, I'd like the feature matching to only apply to products that pass through this set of filters. How would I combine these?
I have found some similar questions like this and this, but they aren't close enough for me to figure out how to apply those solutions to my situation.
The tables involved look something like this:
products (id,product)
features (id, feature)
product_features (id, product_id, feature_id)
and the user will be submitting his search through an array like this (where the keys are actually feature ids, and the rank is the value):
[users_features] => Array
(
[1] => Array
(
[rank] => 9
)
[2] => Array
(
[rank] => 1
)
[3] => Array
(
[rank] => 3
)
(this will be a 10 item array right now, but could change in the future)
)