lib/services/search.rb in Active-0.0.5 vs lib/services/search.rb in Active-0.0.6
- old
+ new
@@ -172,13 +172,16 @@
res = http.start { |http|
http.get("#{searchurl.path}?#{searchurl.query}")
}
- if res.code == '200'
+ # if res.code == '200' or res.code == '307'
+ if (200..307).include?(res.code.to_i)
parsed_json = JSON.parse(res.body)
- parsed_json['_results'].collect { |a| Activity.new(a) }
+ return parsed_json["numberOfResults"] if data.has_key?(:show_number_of_results)
+ query_addl_info= {:endIndex=>parsed_json["endIndex"], :pageSize=>parsed_json["pageSize"], :searchTime=>parsed_json["searchTime"], :numberOfResults=>parsed_json["numberOfResults"]}
+ parsed_json['_results'].collect { |a| Activity.new(a.merge query_addl_info) }
else
raise RuntimeError, "Active Search responded with a #{res.code} for your query."
end
end
@@ -186,11 +189,11 @@
options = {
:api_key => "",
:view => "json",
:facet => Facet.ACTIVITIES,
:sort => Sort.DATE_ASC,
- :radius => "10",
+ :radius => "50",
:meta => "",
:num_results => "10",
:page => "1",
:location => "",
:search => "",
@@ -198,10 +201,12 @@
:channels => nil,
:start_date => "today",
:end_date => "+"
}
options.merge!(arg_options)
+
+ return arg_options[:url] if arg_options.keys.index(:url) #a search url was specified - bypass parsing the options (trending)
options[:location] = CGI.escape(options[:location]) if options[:location]
if options[:keywords].class == String
options[:keywords] = options[:keywords].split(",")
@@ -237,10 +242,12 @@
# @meta = @meta + "+AND+" if @meta!=""
# @meta = @meta + "inmeta:assetTypeId=#{@asset_type_id}"
# end
#
url = "#{SEARCH_URL}/search?api_key=#{options[:api_key]}&num=#{options[:num_results]}&page=#{options[:page]}&l=#{options[:location]}&f=#{options[:facet]}&v=#{options[:view]}&r=#{options[:radius]}&s=#{options[:sort]}&k=#{options[:keywords].join("+")}&m=#{meta_data}"
- # puts url
+ puts "//////"
+ puts url
+ puts "//////"
url
end
private
def self.double_encode_channel str
\ No newline at end of file