I want to create a basic search engine, and I want you to give me some ideas how to filter out the best results for my visitors.
I have three fields regarding a product the user can search in:
- Title
- Category
- Description
I came up with these ideas and I ask you to either competently criticize them or add to them.
- If the search term occurs in all three fields it should be among the first results.
- If it is in two of the fields it is below the results of 1.
- Combine the amount of occurences and output a value in per cent. For instance if in all fields together the term clock appeared 50 times and in all fields together there are 200 words, then the per cent value is 50/200*100 = 25%. Another product entry amounts to say 20% so product one having 25% is listed before product two having 20%.
3
Actually you’re more looking to find a “result ordering” rather than a search algorithm.
Anyway, I would grade the results using a points mechanism. This makes it easier to handle, easier to maintain and to enhance if you wish to. Moreover, it also helps you handling the case of multiple keywords search. This is how it works:
For each keyword the user gave:
- give
a
points for the appearance in the title - give
b
points for the appearance in the category - give
c
points by occurrence in the description.
Sum the total amount of points for each keyword.
Order the list of items by points, from highest to lowest.
By playing with the parameter a
, b
and c
you will change the resulting order. You can then fine-tune your algorithm either by allowing the user to change his preference (and updating the parameters in the background) or you can yourself make your own test and determine which parameters are the best.