Class: Solr::Connection::Base
- Inherits:
-
Object
- Object
- Solr::Connection::Base
- Includes:
- SearchExt
- Defined in:
- lib/solr/connection/base.rb
Overview
Connection adapter decorator
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #add(hash_or_array, opts = {}, &block) ⇒ Object
-
#commit(opts = {}) ⇒ Object
send </commit>.
-
#delete_by_id(ids, opts = {}) ⇒ Object
Delete one or many documents by id solr.delete_by_id 10 solr.delete_by_id([12, 41, 199]).
-
#delete_by_query(queries, opts = {}) ⇒ Object
delete one or many documents by query solr.delete_by_query ‘available:0’ solr.delete_by_query [‘quantity:0’, ‘manu:“FQ”’].
-
#find_by_id(id, params = {}) ⇒ Object
Finds a document by its id.
- #index_info(params = {}) ⇒ Object
-
#initialize(adapter, opts = {}) ⇒ Base
constructor
conection is instance of: Solr::Adapter::HTTP Solr::Adapter::Direct (jRuby only).
-
#map_params(params) ⇒ Object
sets default params etc..
-
#optimize(opts = {}) ⇒ Object
send </optimize>.
-
#query(params) ⇒ Object
send request to the select handler params is hash with valid solr request params (:q, :fl, :qf etc..) if params is not set, the default is :ruby (see opts) if :wt is something other than :ruby, the raw response body is returned otherwise, an instance of Solr::Response::Query is returned NOTE: to get raw ruby, use :wt=>‘ruby’.
-
#rollback(opts = {}) ⇒ Object
send </rollback> NOTE: solr 1.4 only.
-
#update(data, params = {}, auto_commit = nil) ⇒ Object
if :ruby is the :wt, then Solr::Response::Base is returned – there’s not really a way to figure out what kind of handler request this is.
Methods included from SearchExt
Constructor Details
#initialize(adapter, opts = {}) ⇒ Base
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/solr/connection/base.rb', line 13 def initialize(adapter, opts={}) @adapter=adapter opts[:auto_commit]||=false opts[:global_params]||={} default_global_params = { :wt=>:ruby, :echoParams=>'EXPLICIT', :debugQuery=>true } opts[:global_params] = default_global_params.merge(opts[:global_params]) @opts=opts end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/solr/connection/base.rb', line 6 def adapter @adapter end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
6 7 8 |
# File 'lib/solr/connection/base.rb', line 6 def opts @opts end |
Instance Method Details
#add(hash_or_array, opts = {}, &block) ⇒ Object
67 68 69 |
# File 'lib/solr/connection/base.rb', line 67 def add(hash_or_array, opts={}, &block) update .add(hash_or_array, opts, &block) end |
#commit(opts = {}) ⇒ Object
send </commit>
72 73 74 |
# File 'lib/solr/connection/base.rb', line 72 def commit(opts={}) update .commit, opts, false end |
#delete_by_id(ids, opts = {}) ⇒ Object
Delete one or many documents by id
solr.delete_by_id 10
solr.delete_by_id([12, 41, 199])
90 91 92 |
# File 'lib/solr/connection/base.rb', line 90 def delete_by_id(ids, opts={}) update .delete_by_id(ids), opts end |
#delete_by_query(queries, opts = {}) ⇒ Object
delete one or many documents by query
solr.delete_by_query 'available:0'
solr.delete_by_query ['quantity:0', 'manu:"FQ"']
97 98 99 |
# File 'lib/solr/connection/base.rb', line 97 def delete_by_query(queries, opts={}) update .delete_by_query(queries), opts end |
#find_by_id(id, params = {}) ⇒ Object
Finds a document by its id
45 46 47 48 49 |
# File 'lib/solr/connection/base.rb', line 45 def find_by_id(id, params={}) params = map_params(params) params[:q] = 'id:"#{id}"' query params end |
#index_info(params = {}) ⇒ Object
51 52 53 54 55 |
# File 'lib/solr/connection/base.rb', line 51 def index_info(params={}) params = map_params(params) response = @adapter.index_info(params) params[:wt] == :ruby ? Solr::Response::IndexInfo.new(response) : response end |
#map_params(params) ⇒ Object
sets default params etc.. - could be used as a mapping hook type of request should be passed in here? -> map_params(:query, {})
28 29 30 |
# File 'lib/solr/connection/base.rb', line 28 def map_params(params) opts[:global_params].dup.merge(params).dup end |
#optimize(opts = {}) ⇒ Object
send </optimize>
77 78 79 |
# File 'lib/solr/connection/base.rb', line 77 def optimize(opts={}) update .optimize, opts end |
#query(params) ⇒ Object
send request to the select handler params is hash with valid solr request params (:q, :fl, :qf etc..)
if params[:wt] is not set, the default is :ruby (see opts[:global_params])
if :wt is something other than :ruby, the raw response body is returned
otherwise, an instance of Solr::Response::Query is returned
NOTE: to get raw ruby, use :wt=>'ruby'
38 39 40 41 42 |
# File 'lib/solr/connection/base.rb', line 38 def query(params) params = map_params(modify_params_for_pagination(params)) response = @adapter.query(params) params[:wt]==:ruby ? Solr::Response::Query.new(response) : response end |
#rollback(opts = {}) ⇒ Object
send </rollback> NOTE: solr 1.4 only
83 84 85 |
# File 'lib/solr/connection/base.rb', line 83 def rollback(opts={}) update .rollback, opts end |
#update(data, params = {}, auto_commit = nil) ⇒ Object
if :ruby is the :wt, then Solr::Response::Base is returned – there’s not really a way to figure out what kind of handler request this is.
60 61 62 63 64 65 |
# File 'lib/solr/connection/base.rb', line 60 def update(data, params={}, auto_commit=nil) params = map_params(params) response = @adapter.update(data, params) self.commit if auto_commit.nil? ? @opts[:auto_commit]==true : auto_commit params[:wt]==:ruby ? Solr::Response::Update.new(response) : response end |