Why Do It?
This may seem like silly a question at first, as search seems to be everywhere and its usefulness is apparent in so many contexts. The context you should consider though is your application. Ask yourself how search might benefit your application and your users. Keep in mind that search is not a replacement for a good user interface. A good user interface should make it easy for the user to locate what they're looking for on your site, without typing anything into a search box.
There are many browse-dominant users out there that prefer to click rather than put their hands to the keyboard, no matter how prominently you display a search box or how well your search performs.
It shouldn't be a chore for the user to find the contact information on your web site. I've looked at thousands of crappy flash restaurant web sites. If you have a search input box on your website and I have to type "address" into it because I can't find it on the site, there is a problem.
A bad search implementation can hurt the usability of your website. If your search functionality is very unfriendly or unaccommodating when it comes to search terms, people will become frustrated and potentially give up on what they wanted to do at your site. This is especially true of search-dominant users of your site. Your search should be able to handle commas, apostrophes, hyphens and other punctuation.
Deciding What you Need
When implementing search capabilities for a web application, many developers might rush into integrating a known solution without asking a few key questions first. While these questions may seem a given and lead you to the same tool, many people don't ponder too deeply about them and the result is an adequate, but not optimal, search functionality for the application. Let's take a look at some initial considerations.
1. What should be searchable in my application?
Let's say I have an online shopping cart. It seems reasonable that I would want my users to search the products. Which products exactly? Not products that haven't been published from admin yet or discontinued products; and perhaps I don't want to show products that are out of stock. Lay it all out. Everything that you expect to be searchable and the conditions that have to be met.
2. How do I want my users to interact with the search functionality?
How flexible will the search be with what user's type in? Will it show automatic suggestions as the user types? Will it attempt to fix misspellings?
3. Direct linking?
Should particular search terms go straight to a particular page instead of showing results? If there was only one result, it seems obvious to advance the user directly to their goal. Sometimes, in the case of certain search terms, you may still want to lead the user on a very specific journey.
4. How current do search results have to be?
Is it imperative that the product/blog post I just added be immediately available in the search results? If not, how much lag time is acceptable?
5. What kind of search options do I want to provide the user?
Are there advanced search options, including date ranges, sort order and relevancy? Note that you shouldn't overload the user with advanced search options from the start. There should be a simplified version of search that is the default, however the advanced options should be easily accessible.
6. Do certain results rank or weigh higher than others?
For example, If I search for tomato, does your blog post about your grandma's spaghetti recipe come up before the result for the contact page that has my address as 123 Tomato St?
Initial Setup
Once you've decided what is best for your application and its users with regard to the application's search functionality, you can start looking around at the available tools to implement it. You will want to map your search functionality needs to the capabilities provided for by the search tools. See how well these tools perform. Users expect search to be fast, they really don't care how much information you have to go through to find what they want. More than likely, the information you want to search is stored in a database. Ideally, one does not want to do full text searches against the database. It is expensive for the database and if you have a high-traffic site where searches are going to be performed fairly often, steer clear of it.
Instead, many popular search tools bring search outside of the database scope by indexing the data you want searched in your database. This usually means that I will choose the table columns that have the information I want available for search, such as product name and product description. I would then create a script that pulls this data and adds it to my index (note that index size is usually 20-30% of the initial data being indexed, depending on the search tool). You will more than likely want to run this script from a cron job to refresh your index on an interval that is dependent upon your needs. Note that you can add and delete from the index as items are inserted and deleted from your database. This means that your need to refresh the entire index may change if you use this approach.
A big chunk of the work that you will face is the initial index setup work required to provide for the features and conditions you want in place for your search. Features such as wild-card queries, sorting, field weighting, multiple merged indexes, multi-faceting, ranking, result clustering and date ranges are some examples.
Presenting the Results
Depending upon your application and how advanced you want your search to be, you can make assumptions and educated guesses about the intended results. Amazon is a good example. As of the date of this article, typing in "Black Swan" into the search box returns results for "The King's Speech", "The Fighter", and "True Grit"--all within the top 10 search results. Amazon is making the assumption that I may be interested in other Academy Award winning movies. Their end goal is that I will purchase those, as well. This makes sense for Amazon, does it make sense for your application? How search-centered is your application? Factoring in these types of assumptions makes for a lot more complexity in your search application. How long before those Academy Award related search results fade away and I am left with only "Black Swan" results?
Most results are displayed by relevancy, which makes sense; sometimes it makes sense to sort the results by date and can be a helpful option to those perusing the result set. Providing match context in your results can also be helpful. Consider users whose search term matches an exact phrase in an article on the site, but in the search results, only the article title is displayed. While it may be the very article the user was searching for, the user may not realize that they found what they were looking for in that search. Showing match context for the search terms in your display results, where applicable, can be helpful to users.
Often, a user will know meta information about what they want. Information such as, "I know it was in a blog post" or "I know it posted around Christmas time." While we are not mind readers, we can still make it easier for our users to find what they want, based upon the meta data they know.
One way to do this is by clustering your search results into relevant groups. When displaying results, instead of showing the relevant results for everything mixed together, show the relevant results grouped by a strong meta identifier, some example relevancy groups being "Articles", "Products", and "Users", or perhaps by year 2009, 2010, 2011.
Is there a mobile version of your application? How do your search results look there?
Many times, site searches are implemented with Google site search. This is not a bad idea depending upon your site content and search requirements, however keeping those search results contained on your site as opposed to sending the user to a google site search result page, keeps the user engaged on your site and is less confusing than being redirected. Google site search provides for this functionality.
Avoid presenting your search results to look like something from a Google text ad. Many people will think that is what it is and it will be ignored.
Post Implementation
What are people actually searching for? Are you monitoring the queries that are coming through your search form? What are some of the top queries? What results are being given to the user for these queries? Are they what is expected? Most developers will implement search functionality and make sure that it functions, but fail to monitor or provide tests to ensure the search is actually useful after being implemented.
Search is an important part of the web, and the technology behind it is becoming smarter and faster. Take advantage of it, but first take the time to discover your application needs and how you can best serve your users.