Class: RSolr::Connection::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter) ⇒ Base

“adapter” is instance of:

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

or any other class that uses the connection “interface”



16
17
18
# File 'lib/rsolr/connection.rb', line 16

def initialize(adapter)
  @adapter = adapter
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.



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

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

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



10
11
12
# File 'lib/rsolr/connection.rb', line 10

def adapter
  @adapter
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’])



51
52
53
# File 'lib/rsolr/connection.rb', line 51

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

#commitObject

send </commit>



56
57
58
# File 'lib/rsolr/connection.rb', line 56

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])


74
75
76
# File 'lib/rsolr/connection.rb', line 74

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"']


81
82
83
# File 'lib/rsolr/connection.rb', line 81

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

#messageObject

shortcut to RSolr::Message::Builder



86
87
88
# File 'lib/rsolr/connection.rb', line 86

def message
  @message ||= RSolr::Message::Builder.new
end

#optimizeObject

send </optimize>



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

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


39
40
41
42
# File 'lib/rsolr/connection.rb', line 39

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

#rollbackObject

send </rollback> NOTE: solr 1.4 only



67
68
69
# File 'lib/rsolr/connection.rb', line 67

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



27
28
29
# File 'lib/rsolr/connection.rb', line 27

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