mirror of https://github.com/apache/lucene.git
Update example to use _text field name and have explicit require/include code too, suitable for copy/pasting right into irb to work it, and cleaned up output
git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@496939 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
db6cbaa709
commit
59f0a1bc46
|
@ -4,21 +4,24 @@ solrb exposes the power of Solr as a Ruby DSL (domain specific language).
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
|
||||||
First launch Solr.
|
First launch Solr:
|
||||||
|
|
||||||
cd solr
|
cd solr
|
||||||
java -jar start.jar
|
java -jar start.jar
|
||||||
|
|
||||||
In a separate shell, launch irb -Ilib.
|
In a separate shell, launch {{{irb -Ilib}}}:
|
||||||
|
|
||||||
|
require 'solr' # load the library
|
||||||
|
include Solr # Allow Solr:: to be omitted from class/module references
|
||||||
|
|
||||||
# connect to the solr instance
|
# connect to the solr instance
|
||||||
conn = Connection.new('http://localhost:8983/solr', :autocommit => :on)
|
conn = Connection.new('http://localhost:8983/solr', :autocommit => :on)
|
||||||
|
|
||||||
# add a document to the index
|
# add a document to the index
|
||||||
conn.add(:id => 123, :title => 'Lucene in Action')
|
conn.add(:id => 123, :title_text => 'Lucene in Action')
|
||||||
|
|
||||||
# update the document
|
# update the document
|
||||||
conn.update(:id => 123, :title => 'Solr in Action')
|
conn.update(:id => 123, :title_text => 'Solr in Action')
|
||||||
|
|
||||||
# print out the first hit in a query for 'action'
|
# print out the first hit in a query for 'action'
|
||||||
response = conn.query('action')
|
response = conn.query('action')
|
||||||
|
@ -26,7 +29,7 @@ In a separate shell, launch irb -Ilib.
|
||||||
|
|
||||||
# iterate through all the hits for 'action'
|
# iterate through all the hits for 'action'
|
||||||
conn.query('action') do |hit|
|
conn.query('action') do |hit|
|
||||||
puts hit
|
puts hit.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
# delete document by id
|
# delete document by id
|
||||||
|
|
|
@ -70,6 +70,7 @@ module Solr
|
||||||
# end
|
# end
|
||||||
|
|
||||||
def query(query, options={}, &action)
|
def query(query, options={}, &action)
|
||||||
|
# TODO: Shouldn't this return an exception if the Solr status is not ok? (rather than true/false).
|
||||||
options[:query] = query
|
options[:query] = query
|
||||||
request = Solr::Request::Standard.new(options)
|
request = Solr::Request::Standard.new(options)
|
||||||
response = send(request)
|
response = send(request)
|
||||||
|
|
Loading…
Reference in New Issue