Prashant Singh
Prashant Singh

Reputation: 3793

Making an efficient search engine for my website

My database contains tens of millions of products, so I need an efficient search technique to speed up my response. Initially, I tried making a number of tables based on alphabets or some initial characters of the query. However, that fails many times, e.g. if the user searches for "ipod touch" instead of "apple ipod touch." Can I implement this using a trie or some other data structure? How does Google keep track of so much data?

Upvotes: 3

Views: 1137

Answers (2)

Palladium
Palladium

Reputation: 3763

Making your own search algorithm is difficult. When I had to do something similar for a project, I simply trawled the entire database, column by column, searching for all, then any terms; it was crude, but it worked since the database would never realistically hold more than ten thousand entries. Given the size of your database, you're much better off looking into some pre-made search engines: those things are really well written and optimized. As Joyce Babu suggested, Apache Solr is one; another suggestion I'd like to make is Sphinx. It is (according to Wikipedia) used on craigslist where it serves 200 million searches a day; that sort of power should be more than enough to handle what you want.

Upvotes: 5

Joyce Babu
Joyce Babu

Reputation: 20654

What you need is a full text search. You could try using the FULLTEXT index in MySQL and perform a MATCH AGAINST query.

But I think you will have much better luck with Apache Solr. It is fast, scalable and provides much better (relevant) results.

Upvotes: 2

Related Questions