lib/rsolr/connection/utils.rb in rsolr-0.12.1 vs lib/rsolr/connection/utils.rb in rsolr-0.13.0.pre
- old
+ new
@@ -1,7 +1,7 @@
# Helpful utility methods for building queries to a Solr server
-# This includes helpers that the Direct connection can use.
+# This includes helpers that the Direct connection can use -- not specific to http, for example
module RSolr::Connection::Utils
# Performs URI escaping so that you can construct proper
# query strings faster. Use this rather than the cgi.rb
# version since it's faster. (Stolen from Rack).
@@ -17,11 +17,11 @@
def encode_utf8 string
(string.respond_to?(:force_encoding) and string.respond_to?(:encoding)) ?
string.force_encoding(Encoding::UTF_8) : string
end
- # Return the bytesize of String; uses String#length under Ruby 1.8 and
+ # Return the bytesize of String; uses String#size under Ruby 1.8 and
# String#bytesize under 1.9.
if ''.respond_to?(:bytesize)
def bytesize(string)
string.bytesize
end
@@ -51,15 +51,16 @@
end
#
# converts hash into URL query string, keys get an alpha sort
# if a value is an array, the array values get mapped to the same key:
- # hash_to_query(:q=>'blah', :fq=>['blah', 'blah'], :facet=>{:field=>['location_facet', 'format_facet']})
+ # hash_to_query(:q=>'blah-query', :fq=>['f1', 'f1'], :facet=>true, 'facet.field'=>['location_facet', 'format_facet'])
# returns:
- # ?q=blah&fq=blah&fq=blah&facet.field=location_facet&facet.field=format.facet
+ # ?q=blah-query&fq=f1&fq=f2&facet=true&facet.field=location_facet&facet.field=format.facet
#
- # if a value is empty/nil etc., it is not added
+ # if a value is empty/nil etc., it is tossed out
+ #
def hash_to_query(params)
mapped = params.map do |k, v|
next if v.to_s.empty?
if v.class == Array
hash_to_query(v.map { |x| [k, x] })
@@ -67,7 +68,7 @@
build_param k, v
end
end
mapped.compact.join("&")
end
-
+
end
\ No newline at end of file