Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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:

  1. Title
  2. Category
  3. Description

I came up with these ideas and I ask you to either competently criticize them or add to them.

  1. If the search term occurs in all three fields it should be among the first results.
  2. If it is in two of the fields it is below the results of 1.
  3. 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%.
share|improve this question
    
why you don't search by title only, where as category is a drop-down of all existing product categories? what type of database r u using ? –  Yusubov Sep 29 '12 at 15:18
    
@ElYusubov a)Title might not contain the keyword clock but it's brand while description does b)I don't know all products' categories c)MySQL –  Zurechtweiser Sep 29 '12 at 17:49
    
If this is your search requirements, i am ok with it.However, you may refine them as i suggested with categories. –  Yusubov Sep 29 '12 at 17:52
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.