README.rdoc in google_custom_search-0.3.0 vs README.rdoc in google_custom_search-0.3.1

- old
+ new

@@ -1,10 +1,14 @@ = Google Custom Search -Ruby API to Google Custom Search Engine (http://www.google.com/cse). Works with the paid version of CSE where you get results in XML format. +This project is a Ruby API to Google's Custom Search Engine (http://www.google.com/cse). +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). +<b>Google Custom Search is currently compatible with Rails 2.x and Rails 3.</b> + + == 1. Install Install either as a Rails plugin: script/plugin install git://github.com/alexreisner/google_custom_search.git @@ -28,10 +32,17 @@ GOOGLE_SEARCH_CX = "..." You can find the CX value for your custom search engine via the search control panel on Google's site (click the "Get code" link and you'll see a hidden "cx" field in the sample HTML form). +Optionally, you can set default Google search params, such as encoding, by setting up the <tt>GOOGLE_SEARCH_PARAMS</tt> hash in the same initializer: + + GOOGLE_SEARCH_PARAMS = { + :ie => 'utf8', + :oe => 'utf8' + } + If you're working outside of Rails you'll also need some +require+ statements: require 'rubygems' require 'rexml/document' require 'google_custom_search' @@ -43,24 +54,25 @@ results = GoogleCustomSearch.search("Hank Aaron") The +results+ variable is now a GoogleCustomSearch::ResultSet object: - results.total # 5080 - results.pages # array of GoogleCustomSearch::Result objects - results.suggestion # string with suggested search term, if any + 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 |r| - r.title # page title - r.url # page URL - r.description # Google's excerpt, with terms highlighted + results.pages.each do |result| + result.title # result title + result.url # result URL + result.description # excerpt, with terms highlighted end == Future +* prevent NameError when GOOGLE_SEARCH_CX is missing: show nice msg * access to all data returned by Google * support for features of CSE free version * support for multiple CSEs in one app (GOOGLE_SEARCH_CX should be a hash)