lib/nazrin/search_client.rb in nazrin-0.2.0 vs lib/nazrin/search_client.rb in nazrin-1.0.0
- old
+ new
@@ -1,7 +1,11 @@
module Nazrin
+ class SearchClientError < StandardError; end
+
class SearchClient
+ CLOUD_SEARCH_MAX_LIMIT = 10_000
+
attr_accessor :data_accessor
attr_reader :parameters
def initialize
@client = Aws::CloudSearchDomain::Client.new(
@@ -102,17 +106,31 @@
@parameters[:expr] = expr
self
end
def search
+ fail SearchClientError if deep_page?
@client.search(@parameters)
end
def execute
if data_accessor
data_accessor.results(self)
else
search
end
+ end
+
+ private
+
+ def deep_page?
+ if parameters[:start].present? && parameters[:size].present?
+ return true if parameters[:start] + parameters[:size] > CLOUD_SEARCH_MAX_LIMIT
+ elsif parameters[:start].present?
+ return true if parameters[:start] > CLOUD_SEARCH_MAX_LIMIT
+ elsif parameters[:size].present?
+ return true if parameters[:size] > CLOUD_SEARCH_MAX_LIMIT
+ end
+ false
end
end
end