Search code examples
mysqlalgorithmsearch-engineestimation

Mysql - "Best Match" search algorithm


Let's assume I have a table full of teachers.

every teacher has these parameters:

Experience
Hourly Cost
Distance
Last Login
Total Rating (like an eBay score given by student)

the fact is, that I would avoid to give my users those dropdown menus to choose the sorting option, but i would build a search engine smart enough to compute the best match

for best match i mean a good balance of each parameter, so the first results are the teachers who have a recent login, who are closer to you etc...but not necesserely alwasy with the same sorting sequence (login DESC, THEN distance ASc etc...)

example: i set as first parameter of sorting the lastlogin DESC. how to avoid that a teacher (with alow score and faraway from me) that Sign in every day is going to be always first in my results, and maybe a teacher that is only 1mile form me, but he sign in only once a week is going to be penalized for that...

i hope i was clear.. ;)


Solution

  • You can build an estimate function to calculate the relevance from all that parameter, with specific weight for each. Then sort on the result.

    Mostfavorite(teacher) = A(teacher.Experience) + B(teacher.HourlyCost) + C(teacher.Distance) + D(teacher.LastLogin) + E(teacher.TotalRating)