Ruby
Ruby
JSON is the preferred interchange format for Ruby users.
require 'net/http'
require 'json'
h = Net::HTTP.new('localhost', 8983)
http_response = h.get('/solr/techproducts/select?q=iPod&wt=json')
# Parse the JSON response
rsp = JSON.parse(http_response.body)
puts 'Number of matches = ' + rsp['response']['numFound'].to_s
# Print out the name field for each returned document
rsp['response']['docs'].each do |doc|
puts 'Name field = ' + doc['name']
end
You can even skip the wt=json
as it’s the default writer type.
If you are building complex interactions with Solr, then consider these libraries:
Active
-
RSolr: A lightweight, general purpose client library for Solr.
-
Sunspot: A nice DSL framework for integrating Solr into your models. Built on top of RSolr.
-
-
Blacklight: A popular and well-maintained Ruby on Rails framework for building flexible and attractive front-ends to Solr.
Inactive
-
Solr-ruby: Low-level access to Solr from Ruby.
-
Flare: A plugin adding faceted browsing, AJAX suggest, and more to Rails controllers.
-
acts_as_solr: A plugin to add full-text search capabilities using Solr to ActiveRecord models. nice acts_as_solr tutorial
-
acts_as_background_solr: An extension to acts_as_solr moving more processing to the background.
-
Searchable: A Rails plugin that provides search integration with ActiveRecord. (an alternative to acts_as_solr)
-
DelSolr: A Solr wrapper designed to simplify facet and filter queries.