You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2006/09/21 21:42:46 UTC

[Solr Wiki] Update of "SolRuby" by FinnSmith

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 FinnSmith:
http://wiki.apache.org/solr/SolRuby

The comment on the change is:
wrapped code samples in preformatted tag

------------------------------------------------------------------------------
  
  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" : "/
+      post = Net::HTTP::Post.new(mode == :search ? "/solr/select" : "/solr/update")
- solr/update")
       post.body = body
       post.content_type = 'application/x-www-form-urlencoded'
       response = Net::HTTP.start(@url.host, @url.port) do |http|
@@ -45, +45 @@

       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.
  
@@ -67, +72 @@

  
  I'm working with a guy named Lee Marlow on a SOLR backend for [http://mojodna.net/searchable/ruby/ Searchable], which is a Rails plugin that provides search integration with ActiveRecord.  The API looks approximately like this:
  
+ {{{
      class SomeModel
          include Searchable
          index_attr :name, :boost => 2.0
@@ -75, +81 @@

              attr.include :name
          end
      end
+ }}}
  
  Now, to index:
  
+ {{{
      SomeModel.add_to_index # (happens automatically on save/update/destroy)
+ }}}
  
  And to search:
  
+ {{{
      SomeModel.search("year:1865", :offset => 0, :limit 20)
+ }}}
  
  - Seth