2007-02-18 21:20:25 -05:00
|
|
|
solr-ruby exposes the power of Solr as a Ruby DSL (domain specific language).
|
2007-01-02 23:57:00 -05:00
|
|
|
|
2007-02-18 21:20:25 -05:00
|
|
|
Visit the solr-ruby wiki for more information: http://wiki.apache.org/solr/solr-ruby
|
2007-01-02 23:57:00 -05:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
|
2007-01-17 00:44:37 -05:00
|
|
|
First launch Solr:
|
2007-01-02 23:57:00 -05:00
|
|
|
|
2007-01-16 17:02:29 -05:00
|
|
|
cd solr
|
|
|
|
java -jar start.jar
|
2007-01-14 21:43:02 -05:00
|
|
|
|
2007-01-17 00:44:37 -05:00
|
|
|
In a separate shell, launch {{{irb -Ilib}}}:
|
|
|
|
|
|
|
|
require 'solr' # load the library
|
|
|
|
include Solr # Allow Solr:: to be omitted from class/module references
|
2007-01-14 21:43:02 -05:00
|
|
|
|
2007-01-16 17:02:29 -05:00
|
|
|
# connect to the solr instance
|
2007-01-16 17:03:44 -05:00
|
|
|
conn = Connection.new('http://localhost:8983/solr', :autocommit => :on)
|
2007-01-02 23:57:00 -05:00
|
|
|
|
2007-01-16 17:02:29 -05:00
|
|
|
# add a document to the index
|
2007-01-17 00:44:37 -05:00
|
|
|
conn.add(:id => 123, :title_text => 'Lucene in Action')
|
2007-01-02 23:57:00 -05:00
|
|
|
|
2007-01-16 17:02:29 -05:00
|
|
|
# update the document
|
2007-01-17 00:44:37 -05:00
|
|
|
conn.update(:id => 123, :title_text => 'Solr in Action')
|
2007-01-02 23:57:00 -05:00
|
|
|
|
2007-01-16 17:02:29 -05:00
|
|
|
# print out the first hit in a query for 'action'
|
|
|
|
response = conn.query('action')
|
|
|
|
print response.hits[0]
|
2007-01-02 23:57:00 -05:00
|
|
|
|
2007-01-16 17:02:29 -05:00
|
|
|
# iterate through all the hits for 'action'
|
|
|
|
conn.query('action') do |hit|
|
2007-01-17 00:44:37 -05:00
|
|
|
puts hit.inspect
|
2007-01-16 17:02:29 -05:00
|
|
|
end
|
2007-01-02 23:57:00 -05:00
|
|
|
|
2007-01-16 17:02:29 -05:00
|
|
|
# delete document by id
|
|
|
|
conn.delete(123)
|
2007-01-02 23:57:00 -05:00
|
|
|
|
|
|
|
INSTALLATION
|
|
|
|
|
|
|
|
First run the tests:
|
|
|
|
|
2007-01-14 21:43:02 -05:00
|
|
|
rake
|
|
|
|
|
2007-01-02 23:57:00 -05:00
|
|
|
then build the gem:
|
|
|
|
|
|
|
|
rake package
|
|
|
|
|
|
|
|
and install the versioned gem:
|
|
|
|
|
|
|
|
gem install pkg/solr-x.x.x.gem
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
|
|
|
|
This package is licensed using the Apache Software License 2.0.
|
|
|
|
|
|
|
|
<http://www.apache.org/licenses/LICENSE-2.0>
|