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 BrianLucas: http://wiki.apache.org/solr/SolRuby ------------------------------------------------------------------------------ Bindings for integration into Rails: (not finished) + + Erik Hatcher posted the following message on the Solr mailing list for ideas. + + + My current code has not been distilled into a clean API, but it's usable. It all boils down to this: + + def post_to_solr(body, mode = :search) + post = Net::HTTP::Post.new(mode == :search ? "/solr/select" : "/ + solr/update") + post.body = body + post.content_type = 'application/x-www-form-urlencoded' + response = Net::HTTP.start(@url.host, @url.port) do |http| + http.request(post) + end + response_dom = Document.new(response.body) + end + + though using REXML's Document is likely to be pulled out to something more optimal for Ruby ingesting, such as YAML. + + This sits in a Solr class and has utility methods like this: + + def optimize + post_to_solr('<optimize waitFlush="false" waitSearcher="false"/ >', :update) + end + + So I can use IRB (via Rails slick script/console) and do this: + + solr = Solr.new + results = solr.search([{:field => "year", :value => "1865"}], 0, 20) + + I'm tinkering around with various custom request handlers, custom parameters, and faceted results so nothing has settled down into a stable way to do things just yet, so I haven't felt the generalization falling into place yet. I sincerely hope someone Solr/ Lucene/Java and Ruby savvier than I will eventually step up and build a super slick Solr Ruby DSL :) But it needs to be more flexible than just the standard request handler to be of use to me, so it's more complex than meets the eye. + + Erik +
