Module: RSolr::Uri
Instance Method Summary collapse
-
#build_param(k, v, escape = true) ⇒ Object
deprecated
Deprecated.
-
used to be called from params_to_solr before 2015-02-25
-
- #bytesize(string) ⇒ Object
- #create(url) ⇒ Object
- #escape_query_value(s) ⇒ Object deprecated Deprecated.
-
#params_to_solr(params, escape = true) ⇒ String
Creates a Solr based query string.
Instance Method Details
#build_param(k, v, escape = true) ⇒ Object
Deprecated.
-
used to be called from params_to_solr before 2015-02-25
Returns a query string param pair as a string. Both key and value are URI escaped, unless third param is false
35 36 37 38 39 40 |
# File 'lib/rsolr/uri.rb', line 35 def build_param(k, v, escape = true) warn "[DEPRECATION] `RSolr::Uri.build_param` is deprecated. Use `URI.encode_www_form_component` or k=v instead." escape ? "#{URI.encode_www_form_component(k)}=#{URI.encode_www_form_component(v)}" : "#{k}=#{v}" end |
#bytesize(string) ⇒ Object
62 63 64 65 |
# File 'lib/rsolr/uri.rb', line 62 def bytesize(string) warn "[DEPRECATION] `RSolr::Uri.bytesize` is deprecated. Use String.bytesize" string.bytesize end |
#create(url) ⇒ Object
5 6 7 |
# File 'lib/rsolr/uri.rb', line 5 def create url ::URI.parse (url[-1] == '/' || URI.parse(url).query) ? url : "#{url}/" end |
#escape_query_value(s) ⇒ Object
Deprecated.
2015-02 Deprecated: use URI.encode_www_form_component(s)
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).
http://www.rubydoc.info/github/rack/rack/URI.encode_www_form_component
50 51 52 53 54 55 56 |
# File 'lib/rsolr/uri.rb', line 50 def escape_query_value(s) warn "[DEPRECATION] `RSolr::Uri.escape_query_value` is deprecated. Use `URI.encode_www_form_component` instead." URI.encode_www_form_component(s) # s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/u) { # '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase # }.tr(' ', '+') end |
#params_to_solr(params, escape = true) ⇒ String
Creates a Solr based query string. Keys that have arrays values are set multiple times:
params_to_solr(:q => 'query', :fq => ['a', 'b'])
is converted to:
?q=query&fq=a&fq=b
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rsolr/uri.rb', line 16 def params_to_solr(params, escape = true) return URI.encode_www_form(params.reject{|k,v| k.to_s.empty? || v.to_s.empty?}) if escape # escape = false if we are here mapped = params.map do |k, v| next if v.to_s.empty? if v.class == Array params_to_solr(v.map { |x| [k, x] }, false) else "#{k}=#{v}" end end mapped.compact.join("&") end |