lib/inquisitio/search_url_builder.rb in inquisitio-0.0.11 vs lib/inquisitio/search_url_builder.rb in inquisitio-0.0.12

- old
+ new

@@ -25,12 +25,23 @@ def simple_query "q=#{URI.encode(@query.gsub('\'',''))}" end def boolean_query - filters = @filters.map{|key,value| "#{key.to_s.gsub('\'','')}:'#{value.to_s.gsub('\'','')}'"} + filters = @filters.map do |key,value| + key = key.to_s.gsub('\'','') + + if value.is_a?(String) + "#{key}:'#{value.to_s.gsub('\'','')}'" + elsif value.is_a?(Array) + mapping = value.map {|v| "#{key}:'#{v.to_s.gsub('\'','')}'" }.join(" ") + "(or #{mapping})" + else + raise InquisitioError.new("Filter values must be strings or arrays.") + end + end queries = filters.join(" ") - queries = "'#{@query.gsub('\'','')}' #{queries}" if @query + queries = "'#{@query.to_s.gsub('\'','')}' #{queries}" if @query "bq=#{URI.encode("(and #{queries})")}" end def return_fields_query_string return "" if @return_fields.nil?