Solr has an optional Ruby response format that extends its JSON output in the following ways to allow the response to be safely eval'd by Ruby's interpreter:
Here is a simple example of how one may query Solr using the Ruby response format:
require 'net/http' h = Net::HTTP.new('localhost', 8983) hresp, data = h.get('/solr/select?q=iPod&wt=ruby') rsp = eval(data) puts 'number of matches = ' + rsp['response']['numFound'].to_s #print out the name field for each returned document rsp['response']['docs'].each { |doc| puts 'name field = ' + doc['name'] } |
For simple interactions with Solr, this may be all you need! If you are building complex interactions with Solr, then look at some of the libraries below. Craig L Russell Note: in Ruby 1.9, the encoding of the response may be set to ASCII-8BITS even though Solr responds with UTF-8. See Ruby issue 2567.