Class: Asari
- Inherits:
-
Object
- Object
- Asari
- Defined in:
- lib/makasi/asari_patch.rb
Overview
Allow the new api syntax of version 2013-01-01
Defined Under Namespace
Classes: Collection
Instance Method Summary collapse
Instance Method Details
#search(term, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/makasi/asari_patch.rb', line 26 def search(term, = {}) return Asari::Collection.sandbox_fake if self.class.mode == :sandbox term, = "",term if term.is_a?(Hash) and .empty? if [:filter] bq = boolean_query([:filter]) bq = "(and '#{term.to_s.gsub("'", " ")}' #{bq})" if term.present? end page_size = [:page_size].nil? ? 10 : [:page_size].to_i url = "http://search-#{search_domain}.#{aws_region}.cloudsearch.amazonaws.com/#{api_version}/search" if [:filter] url += "?q.parser=structured&q=#{CGI.escape(bq)}" else url += "?q=#{CGI.escape(term.to_s)}" end url += "&size=#{page_size}" url += "&return-fields=#{[:return_fields].join ','}" if [:return_fields] if [:page] start = ([:page].to_i - 1) * page_size url << "&start=#{start}" end if [:rank] rank = normalize_rank([:rank]) url << "&rank=#{rank}" end begin response = HTTParty.get(url) rescue Exception => e ae = Asari::SearchException.new("#{e.class}: #{e.} (#{url})") ae.set_backtrace e.backtrace raise ae end unless response.response.code == "200" raise Asari::SearchException.new("#{response.response.code}: #{response.response.msg} (#{url})") end Asari::Collection.new(response, page_size) end |