Adding Search to Your Site

by Devanshu Mehta

Recently, a fellow blogger asked me for help getting “search” working on their blog. Since my advice was helpful there, I figured there must be other people who could benefit from the information. So here is how you can add a search feature to your web site regardless of how it was built and regardless of the purpose you choose to use it for. You can use it for your own reference or to allow visitors to search your site. Best of all, it’s quite simple to implement.

If you use a blogging software, like WordPress, it will usually include some in-built search capability (look at the search box on this site; it is part of WordPress). If you use an online service (e.g. TypePad), things may be trickier. And if your site is not a blog at all, and if it is not even scripted (i.e. written in PHP, ASP, code), things could get strange. The beauty of the tips below is that they will work for any web site.

The easiest way I can think of is “to use Google”:http://services.google.com/searchcode2.html?accept=on#both. If Google has indexed your web site- and if it hasn’t, you have other issues- you can leverage Google’s index to search your site. Adding “this code”:http://services.google.com/searchcode2.html?accept=on#both is equivalent to searching Google with “site:yoursite.com”. For example, for this blog, if I wanted to search for the word Google, I would enter ‘site:scienceaddiction.com google’ in Google and get the correct results.

As long as Google has indexed your web site- and does so regularly- you can add the code on the page above which will add a Search box powered by Google. Make sure you change the words “YOUR DOMAIN NAME” to http://yourcorrecturl.com. “TypePad”:http://support.typepad.com/cgi-bin/typepad.cfg/php/enduser/std_adp.php?p_faqid=177 also suggests the same method.

In the past, I have also used “FreeFind.com”:http://www.freefind.com which is quite good at indexing any kind of web site on a regular basis. They have a free version of their service that is slightly limited, but very useful.

One final word, the above suggested Google search method is fine, except that the results page will look like a regular Google page. If you want to have the results look more like your site design, you could sign up with “Google Adsense”:https://www.google.com/adsense/ws-overview?hl=en_GB. This would also allow you to make money off advertising on the search result pages. This may not be your goal at the moment, but it is something to keep in mind. Of course, the drawback of using Google for your search results is that it is updated only when Google indexes your site; which may not be very often. So, your mileage may vary.

Advertisements