Google Custom Search

Updated 14 Oct 2009

If you want a Google-like search engine for your web site, why not use Google? For $100/yr (more if you have over 1,000 pages) you can get access to Google search results for your site in XML format. The google_custom_search gem helps you access this web service and publish the results on your site however you like (all covered under Google’s acceptable use policy).

To perform a search:

results = GoogleCustomSearch.search("Hank Aaron")

The results variable is now a GoogleCustomSearch::ResultSet object:

results.total            # number of results (integer)
results.pages            # array of result objects
results.suggestion       # suggested search term, if any

Iterate through the results:

results.pages.each do |result|
  result.title           # result title
  result.url             # result URL
  result.description     # excerpt, with terms highlighted
end

For source code, installation instructions, and up-to-date API documentation please see the project page at GitHub.