The Search Algorithm in Online Stores

Originally published in Romanian in 2009.

Today I read an article on this topic on the USBmania blog and it reminded me of the little video from the usability tests at GPEC 2009 (Romania’s main e-commerce conference). What happened there? The customer wanted to buy a set of batteries and, searching for the word “batteries”, got results that had absolutely nothing to do with what he wanted, namely all sorts of products that run on batteries. And it reminded me of the search algorithm for online stores that I came up with a while back.

USBmaniaCautare

Things are still the same today and, in the post I mentioned, USBmania says this is fine, that it’s normal, after searching the title, description and product code, to get results like these. Well, allow me to disagree. I’m not doing it out of spite or dislike: I really like that online store and we’re not competitors in any way, so I want them to do better and better. I’m doing it for 2 reasons:

1. because I believe absolutely that no “something” on a website is ok when the result of that “something” is different from what the user expects / wants (this is an axiom of what we call usability or UX – User Experience);

2. because I racked my brain over this, together with a few other bubbling minds, for a long stretch of time, and we ran a number of tests on a store with over 20,000 products (MarketOnline at the time) to find a solution to this search problem.

And since there are 2 reasons, I’m offering USBmania (and obviously not just them) 2 solutions, free of charge:

1. The simple solution: the algorithm searches the title, description and code, but in stages.

First you display the products where the search term appears in the title, the code and the description (that is, in all 3, to be clear). You can list them alphabetically or, for better UX, by the number of times the term repeats in each of the 3 search areas, or, even more relevant, by position: the closer the search term is to the beginning of the title, code or description, the more relevant the product. In the battery example, “battery-AA-024” would be more relevant than “USB bunny with batteries”.

Then we display products where the search term appears in the title and code (2 out of 3), then in the title and description (also 2 out of 3), then in the code and description (again 2 out of 3).

Finally, we display products where the search term appears only in the title (although that’s a sign the description wasn’t written very well).

We don’t display products where the search term appears only in the code or only in the description, so we don’t end up with disasters like the one at GPEC or the one below (I picked eMag, the market leader and Romania’s largest online retailer, since it’s supposed to have the best on-site search too):

USBmaniaCautare2

2. The more complicated solution: you search the code, title, images, URL, comments and whatever else comes to mind, then you calculate a “score” using a representative algorithm (which depends on the store). Let’s say: term in the first half of the title = 10 points, term in the second half of the title = 7 points, term in the code = 5 points, term in the first 10 words of the description = 3 points, in the first 20 = 2 points, in the rest of the description = 1 point, term in the image file name = 2 points, term in the comments = 1 point, and so on. Then we set a minimum number of points for a product to show up in the results, let’s say 3. The search results are displayed starting with the product with the highest score, down to the ones that just reach the minimum. In our case, a product that contains the word “batteries” in its description but not in the first 10 words, and not in the title, code, image or comments either, as with the USBmania search results that started this whole discussion, would have scored under 3 points and wouldn’t have been displayed.

One more thing worth mentioning: I recommend only allowing searches for words of at least 3 letters, otherwise you get even bigger absurdities, like the one below:

USBmaniaCautare1