Use Google's API to search your rails site
Culled from various places on the 'net. This lets you use the Google API to do searching on your site. You'll need to get an API key from Google and abide by their usage terms etc. etc.
In search controller...
The above expects to be called with a request parameter 'term' containing the actual search terms.
Then in your view (e.g. search.rhtml)...
Needs to be extended to handle paging the results but you get the idea.
In search controller...
def search require 'soap/wsdlDriver' @title = 'Search Results' key = 'YOUR GOOGLE API KEY HERE' yoursite = 'YOUR SITE ADDRESS HERE' driver = SOAP::WSDLDriverFactory.new("http://api.google.com/GoogleSearch.wsdl").createDriver @results = driver.doGoogleSearch(key, @params['term']+" site:#{yoursite}", 0, 10, true, " ", false, " ", " ", " ") end
The above expects to be called with a request parameter 'term' containing the actual search terms.
Then in your view (e.g. search.rhtml)...
<% for result in @results.resultElements %>><%= result.title %>
<%
= result.snippet %>> <p><a href="<%= result.URL %>"><%= result.URL %> <% end %>
Needs to be extended to handle paging the results but you get the idea.