Class: Solr::Client
- Inherits:
-
Object
show all
- Includes:
- Codec
- Defined in:
- lib/solr-client.rb
Overview
Constant Summary
collapse
- VERSION =
"0.0.1"
Constants included
from Codec
Solr::Codec::ALLOWED_ADD_ATTRS
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add(docs, options = {}, &block) ⇒ Object
-
#commit(options = {}, &block) ⇒ Object
-
#delete_all(options = {}, &block) ⇒ Object
-
#delete_by_id(id, options = {}, &block) ⇒ Object
-
#delete_by_query(query, options = {}, &block) ⇒ Object
-
#full? ⇒ Boolean
-
#initialize(base_url, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#optimize(options = {}, &block) ⇒ Object
-
#reset ⇒ Object
-
#rollback(options = {}, &block) ⇒ Object
-
#select(query, options = {}, &block) ⇒ Object
execute a search request.
-
#stop ⇒ Object
Methods included from Codec
#to_delete_by_id, #to_delete_by_query, #to_docs
Constructor Details
#initialize(base_url, options = {}) ⇒ Client
Returns a new instance of Client.
141
142
143
144
145
146
147
148
|
# File 'lib/solr-client.rb', line 141
def initialize(base_url, options = {})
@base_url = base_url.gsub(/\/$/, '')
@max_connects = options[:max_connects] || 10
@stop = false
@queue = Queue.new
@multi = Curl::Multi.new
@multi.max_connects = @max_connects
end
|
Instance Attribute Details
#core ⇒ Object
Returns the value of attribute core.
139
140
141
|
# File 'lib/solr-client.rb', line 139
def core
@core
end
|
Instance Method Details
#add(docs, options = {}, &block) ⇒ Object
205
206
207
208
|
# File 'lib/solr-client.rb', line 205
def add(docs, options = {}, &block)
data = lambda { to_docs(docs, options) }
execute Request.new(real_url(options), data, &block)
end
|
#commit(options = {}, &block) ⇒ Object
176
177
178
179
|
# File 'lib/solr-client.rb', line 176
def commit(options = {}, &block)
url = real_url(options) + "?commit=true"
execute Request.new(url, &block)
end
|
#delete_all(options = {}, &block) ⇒ Object
191
192
193
|
# File 'lib/solr-client.rb', line 191
def delete_all(options = {}, &block)
delete_by_query("*:*", options, &block)
end
|
#delete_by_id(id, options = {}, &block) ⇒ Object
195
196
197
198
|
# File 'lib/solr-client.rb', line 195
def delete_by_id(id, options = {}, &block)
data = to_delete_by_id(id)
execute Request.new(real_url(options), data, &block)
end
|
#delete_by_query(query, options = {}, &block) ⇒ Object
200
201
202
203
|
# File 'lib/solr-client.rb', line 200
def delete_by_query(query, options = {}, &block)
data = to_delete_by_query(query)
execute Request.new(real_url(options), data, &block)
end
|
#full? ⇒ Boolean
224
225
226
|
# File 'lib/solr-client.rb', line 224
def full?
@queue.size > @max_connects
end
|
#optimize(options = {}, &block) ⇒ Object
186
187
188
189
|
# File 'lib/solr-client.rb', line 186
def optimize(options = {}, &block)
url = real_url(options) + "?optimize=true"
execute Request.new(url, &block)
end
|
#reset ⇒ Object
219
220
221
222
|
# File 'lib/solr-client.rb', line 219
def reset
stop
@stop = false
end
|
#rollback(options = {}, &block) ⇒ Object
181
182
183
184
|
# File 'lib/solr-client.rb', line 181
def rollback(options = {}, &block)
url = real_url(options) + "?rollback=true"
execute Request.new(url, &block)
end
|
#select(query, options = {}, &block) ⇒ Object
execute a search request.
- query
-
query parameters, keys:
q: query
qt: query type
fq: filter query
fl: specify a set of fields to return, * means all fields
sort: sort method, default value is score desc
start: offset in result set
rows: maximum number of documents to return, default value is 10
defType: specify the query parser
ref:
http://wiki.apache.org/solr/CoreQueryParameters
http://wiki.apache.org/solr/CommonQueryParameters
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/solr-client.rb', line 165
def select(query, options={}, &block)
query[:wt] = "ruby"
options[:action] = "select"
url = real_url(options)
url += '?' unless (url =~ /\?/)
url += '&' if (url =~ /&/)
url += query.map {|k, v| "#{escape(k)}=#{escape(v)}"}.join("&")
execute Request.new(url, &block)
end
|
#stop ⇒ Object
210
211
212
213
214
215
216
217
|
# File 'lib/solr-client.rb', line 210
def stop
@stop = true
if @thread
@queue.push nil
@thread.join
@thread = nil
end
end
|