I am currently planning an upcoming project and am looking for an algorithm for searching a database.
The search is as follows; There will be some specifically labelled criteria (or fields) and I would like to find any objects in which its fields match the specified criteria. As well as this it needs to rank partial results based on the number matches for each field.
Heres an example -
Person 1
Name: John
Occupation: Developer
Favourite Colour: Blue
Person 2
Name: John
Occupation: Manager
Favourite Colour: Blue
Person 3
Name: John
Occupation: Developer
Favourite Colour: Green
Person 4
Name: Larry
Occupation: Mailman
Favourite Colour: Red
Search Criteria
Name: John
Occupation: Developer
Favourite Colour: Blue
Results
Rank 1
Person 1
Rank 2
Person 2
Person 3
The ranks would not be visible but would handle the order of the result list.
I could do this quite easily for a small data set, for example, JavaScript;
results = [];
for(var i = 0; i < objects.length; i++) {
var result = _.intersection(criteria, object[i]);
if(result.length > 0) {
object[i].rank = result.length;
results.push(object[i])
}
}
return results (and order by rank)
Obviously this won't work when querying a db but I am hoping someone much smarter than me can point me in the right direction. I feel like there must be a solution to this out there and it's probably simple but my Google-fu is failing me.