Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change 
notification.

The following page has been changed by YonikSeeley:
http://wiki.apache.org/solr/SolRuby

The comment on the change is:
ruby response format

------------------------------------------------------------------------------
+ == Using Solr's Ruby output ==
+ 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:
+  * Ruby's single quoted strings are used to prevent possible string exploits
+   * \ and ' are the only two characters escaped...
+   * unicode escapes not used... data is written as raw UTF-8
+  * nil used for null
+  * => used as the key/value separator in maps
+ 
+ 
+ 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', nil)
+ 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'] }
+ }}}
+ 
+ 
+ == Ruby on Rails ==
  In Ruby on Rails, the concept of models can extend beyond a local database.  
As SOLR functions as a web service, it makes sense to have Ruby query the SOLR 
web service, parse the returned XML document, and have the data work in the 
same fashion as a database model would.
  
  Bindings for integration into Rails: (not finished)

Reply via email to