Skip to content

Commit

Permalink
Move force_to_utf8 from SolrHelper to SolrResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Mar 31, 2014
1 parent 10a70e5 commit 840adf5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
14 changes: 1 addition & 13 deletions lib/blacklight/solr_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ module Blacklight::SolrHelper

end

def force_to_utf8(value)
case value
when Hash
value.each { |k, v| value[k] = force_to_utf8(v) }
when Array
value.each { |v| force_to_utf8(v) }
when String
value.force_encoding("utf-8") if value.respond_to?(:force_encoding)
end
value
end

##
# Execute a solr query
# @see [RSolr::Client#send_and_receive]
Expand All @@ -93,7 +81,7 @@ def find(*args)
key = blacklight_config.http_method == :post ? :data : :params
res = blacklight_solr.send_and_receive(path, {key=>solr_params.to_hash, method:blacklight_config.http_method})

solr_response = Blacklight::SolrResponse.new(force_to_utf8(res), solr_params, solr_document_model: blacklight_config.solr_document_model)
solr_response = Blacklight::SolrResponse.new(res, solr_params, solr_document_model: blacklight_config.solr_document_model)

Rails.logger.debug("Solr query: #{solr_params.inspect}")
Rails.logger.debug("Solr response: #{solr_response.inspect}") if defined?(::BLACKLIGHT_VERBOSE_LOGGING) and ::BLACKLIGHT_VERBOSE_LOGGING
Expand Down
16 changes: 15 additions & 1 deletion lib/blacklight/solr_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class Blacklight::SolrResponse < HashWithIndifferentAccess

attr_reader :request_params
attr_accessor :solr_document_model

def initialize(data, request_params, options = {})
super(data)
super(force_to_utf8(data))
@request_params = request_params
self.solr_document_model = options[:solr_document_model] || SolrDocument
end
Expand Down Expand Up @@ -75,4 +76,17 @@ def grouped?
self.has_key? "grouped"
end

private

def force_to_utf8(value)
case value
when Hash
value.each { |k, v| value[k] = force_to_utf8(v) }
when Array
value.each { |v| force_to_utf8(v) }
when String
value.force_encoding("utf-8") if value.respond_to?(:force_encoding)
end
value
end
end

0 comments on commit 840adf5

Please sign in to comment.