lib/thinking_sphinx/search.rb in friendlyfashion-thinking-sphinx-2.0.13.3 vs lib/thinking_sphinx/search.rb in friendlyfashion-thinking-sphinx-2.0.14.1
- old
+ new
@@ -357,17 +357,19 @@
end
populate
index = options[:index] || "#{model.core_index_names.first}"
- client.excerpts(
- {
- :docs => [string.to_s],
- :words => query,
- :index => index.split(',').first.strip
- }.merge(options[:excerpt_options] || {})
- ).first
+ take_client do |client|
+ client.excerpts(
+ {
+ :docs => [string.to_s],
+ :words => query,
+ :index => index.split(',').first.strip
+ }.merge(options[:excerpt_options] || {})
+ ).first
+ end
end
def search(*args)
args << args.extract_options!.merge(:ignore_default => true)
merge_search ThinkingSphinx::Search.new(*args), self.args, options
@@ -389,14 +391,20 @@
args << options
ThinkingSphinx::FacetSearch.new(*args)
end
- def client
- client = options[:client] || config.client
-
- prepare client
+ def take_client
+ if options[:client]
+ prepare options[:client]
+ yield options[:client]
+ else
+ ThinkingSphinx::Connection.take do |client|
+ prepare client
+ yield client
+ end
+ end
end
def append_to(client)
prepare client
client.append_query query, indexes, comment
@@ -424,16 +432,18 @@
begin
retry_on_stale_index do
retry_on_index_not_preread do
begin
+ @results = nil
log query do
- @results = client.query query, indexes, comment
+ take_client do |client|
+ @results = client.query query, indexes, comment
+ end
end
total = @results[:total_found].to_i
log "Found #{total} result#{'s' unless total == 1}"
-
log "Sphinx Daemon returned warning: #{warning}" if warning?
if error?
log "Sphinx Daemon returned error: #{error}"
raise SphinxError.new(error, @results) unless options[:ignore_errors]
@@ -468,10 +478,10 @@
compose_only_results
else
replace instances_from_matches
add_excerpter
add_sphinx_attributes
- add_matching_fields if client.rank_mode == :fieldmask
+ add_matching_fields if options[:rank_mode] == :fieldmask
end
end
def compose_ids_results
replace @results[:matches].collect { |match|