mysql - ruby on rails database entry matching, storage -


this kind of strange question, try explain best of ability.

let's have following 2 tables:

table: cars  +---------------+------------+----------------+--------------+ |     color     |    size    |    capacity    |    origin    | +---------------+------------+----------------+--------------+  table: users  +----------------+---------------+--------------------+-----------------+ | desired_colors | desired_sizes | desired_capacities | desired_origins | +----------------+---------------+--------------------+-----------------+ 

obviously cars table consist of unique cars color, size, capacity , origin.

in users table, there user selections of multiple colors want, multiple sizes want, multiple capacities want , multiple origins want.

now, i'm wondering best way achieve 'match score' between users desired traits , each vehicle. way, users can see top matches of cars want.

i have few ideas on how this, wondering here thought best way go this. i'm thinking best way have 'matches' table showing match between user_id, car_id , match_score -- i'm not sure how , when run these calculations , save data. thing think if decide change criteria scores.

anyways, know weird question , might not many answers, hoping stir pot , see if has ideas.

thanks :)

i determine matches in query, rather store in table. if dataset expected huge, may more efficient pre-calculate matches, in likelihood, premature optimization. so, load desired features when user logs in, run query such this:

select *,  if(color in ('green', 'red', blue', ...), 10, 0)  + if(size in (...), 10, 0)  + if(capacity in (...), 10, 0)  + if(origin in (...), 10, 0) score cars color in ('green', 'red', blue', ...) or size in (...) or capacity in (...) or origin in (...) 

Comments