In Files

RSolr::Uri

Public Instance Methods

build_param(k,v, escape = true) click to toggle source

Returns a query string param pair as a string. Both key and value are escaped.

# File lib/rsolr/uri.rb, line 11
def build_param(k,v, escape = true)
  escape ? 
    "#{escape_query_value(k)}=#{escape_query_value(v)}" :
    "#{k}=#{v}"
end
bytesize(string) click to toggle source
# File lib/rsolr/uri.rb, line 20
def bytesize(string)
  string.bytesize
end
create(url) click to toggle source
# File lib/rsolr/uri.rb, line 5
def create url
  ::URI.parse url[-1] == // ? url : "#{url}/"
end
escape_query_value(s) click to toggle source

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).

# File lib/rsolr/uri.rb, line 50
def escape_query_value(s)
  s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/) {
    '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
  }.tr(' ', '+')
end
params_to_solr(params, escape = true) click to toggle source

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
# File lib/rsolr/uri.rb, line 34
def params_to_solr(params, escape = true)
  mapped = params.map do |k, v|
    next if v.to_s.empty?
    if v.class == Array
      params_to_solr(v.map { |x| [k, x] }, escape)
    else
      build_param k, v, escape
    end
  end
  mapped.compact.join("&")
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.