Sha256: 5c0cb34a5fff2a1b22d9ba5418f5fe4a1b15f9f6644f3eae763404772ddb0e03

Contents?: true

Size: 980 Bytes

Versions: 1

Compression:

Stored size: 980 Bytes

Contents

module CloudSesame
	module Query
		module DSL
			module ResponseMethods

				def response
					@response ||= search
				end

				# ENDING METHODS
				# =========================================

				def found
					response.hits.found
				end

				def results
					response.hits.hit
				end

				def each(&block)
					results.each &block
				end

				def map(&block)
					results.map &block
				end

				def search
					compiled = request.compile
					raise Error::MissingQuery.new("Query or FilterQuery can not be empty!") if !compiled[:query] || compiled[:query].empty?
					if context[:cache]
						compiled[:searchable] = searchable
						@response = Rails.cache.fetch(compiled) do
							results = @searchable.cloudsearch.client.search compiled
						  OpenStruct.new(status: results.status, hits: results.hits, facets: results.facets)
						end
					else
						@response = @searchable.cloudsearch.client.search compiled
					end
					@response
				end

			end
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
CloudSesame-0.6.1 lib/cloud_sesame/query/dsl/response_methods.rb