lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Solr Wiki] Update of "solrb" by ErikHatcher
Date Wed, 17 Jan 2007 04:46:16 GMT
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 ErikHatcher:
http://wiki.apache.org/solr/solrb

------------------------------------------------------------------------------
   * (in a separate shell) Launch IRB: {{{cd solrb ; irb -Ilib}}}
  
  {{{
- irb(main):001:0> require 'solr'
- irb(main):002:0> conn = Solr::Connection.new('http://localhost:8983/solr')
+   require 'solr'  # load the library
+   include Solr    # Allow Solr:: to be omitted from class/module references
+ 
+   # connect to the solr instance
+   conn = Connection.new('http://localhost:8983/solr', :autocommit => :on)
+ 
+   # add a document to the index
+   conn.add(:id => 123, :title_text => 'Lucene in Action')
+ 
+   # update the document
- irb(main):003:0> conn.add(:id => 529, :title_text => 'Solr in Action')
+   conn.update(:id => 123, :title_text => 'Solr in Action')
- irb(main):004:0> conn.commit
- irb(main):005:0> require 'pp'
- irb(main):005:0> conn.query('solr') {|hit| pp hit}
- {"score"=>0.37158427, "id"=>"529", "title_text"=>["Solr in Action"]}
- irb(main):006:0> conn.delete(529)
- irb(main):007:0> conn.commit
+ 
+   # print out the first hit in a query for 'action'
+   response = conn.query('action')
+   print response.hits[0]
+ 
+   # iterate through all the hits for 'action'
+   conn.query('action') do |hit|
+     puts hit.inspect
+   end
+ 
+   # delete document by id
+   conn.delete(123)
  }}}
   
  

Mime
View raw message