Class: RSolr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rsolr/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Client

“connection” is instance of:

RSolr::Adapter::HTTP
RSolr::Adapter::Direct (jRuby only)

or any other class that uses the connection “interface”



9
10
11
# File 'lib/rsolr/client.rb', line 9

def initialize(connection)
  @connection = connection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &blk) ⇒ Object

Send a request to a request handler using the method name. Also proxies to the #paginate method if the method starts with “paginate_”



15
16
17
# File 'lib/rsolr/client.rb', line 15

def method_missing(method_name, *args, &blk)
  request("/#{method_name}", *args, &blk)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/rsolr/client.rb', line 3

def connection
  @connection
end

Instance Method Details

#add(doc, &block) ⇒ Object

single record: solr.update(:id=>1, :name=>‘one’)

update using an array solr.update([:name=>‘one’, :name=>‘two’])



45
46
47
# File 'lib/rsolr/client.rb', line 45

def add(doc, &block)
  update message.add(doc, &block)
end

#commitObject

send </commit>



50
51
52
# File 'lib/rsolr/client.rb', line 50

def commit
  update message.commit
end

#delete_by_id(id) ⇒ Object

Delete one or many documents by id

solr.delete_by_id 10
solr.delete_by_id([12, 41, 199])


68
69
70
# File 'lib/rsolr/client.rb', line 68

def delete_by_id(id)
  update message.delete_by_id(id)
end

#delete_by_query(query) ⇒ Object

delete one or many documents by query

solr.delete_by_query 'available:0'
solr.delete_by_query ['quantity:0', 'manu:"FQ"']


75
76
77
# File 'lib/rsolr/client.rb', line 75

def delete_by_query(query)
  update message.delete_by_query(query)
end

#message(*opts) ⇒ Object

shortcut to RSolr::Message::Generator



80
81
82
# File 'lib/rsolr/client.rb', line 80

def message *opts
  @message ||= RSolr::Message::Generator.new
end

#optimizeObject

send </optimize>



55
56
57
# File 'lib/rsolr/client.rb', line 55

def optimize
  update message.optimize
end

#request(path, params = {}, *extra) ⇒ Object

send request solr params is hash with valid solr request params (:q, :fl, :qf etc..)

if params[:wt] is not set, the default is :ruby
if :wt is something other than :ruby, the raw response body is used
otherwise, a simple Hash is returned
NOTE: to get raw ruby, use :wt=>'ruby' <- a string, not a symbol like :ruby


33
34
35
36
# File 'lib/rsolr/client.rb', line 33

def request(path, params={}, *extra)
  response = @connection.request(path, map_params(params), *extra)
  adapt_response(response)
end

#rollbackObject

send </rollback> NOTE: solr 1.4 only



61
62
63
# File 'lib/rsolr/client.rb', line 61

def rollback
  update message.rollback
end

#update(data, params = {}) ⇒ Object

sends data to the update handler data can be a string of xml, or an object that returns xml from its #to_xml method



21
22
23
# File 'lib/rsolr/client.rb', line 21

def update(data, params={})
  request '/update', params, data
end