lib/search_flip/criteria.rb in search_flip-3.9.0 vs lib/search_flip/criteria.rb in search_flip-4.0.0.beta

- old
+ new

@@ -24,12 +24,11 @@ include Aggregatable extend Forwardable attr_accessor :target, :profile_value, :source_value, :suggest_values, :includes_values, :eager_load_values, :preload_values, :failsafe_value, :scroll_args, :terminate_after_value, - :timeout_value, :preference_value, :search_type_value, :routing_value, :track_total_hits_value, - :http_timeout_value + :timeout_value, :preference_value, :search_type_value, :routing_value, :track_total_hits_value # Creates a new criteria while merging the attributes (constraints, # settings, etc) of the current criteria with the attributes of another one # passed as argument. For multi-value contstraints the resulting criteria # will include constraints of both criterias. For single-value constraints, @@ -46,11 +45,11 @@ fresh.tap do |criteria| [ :profile_value, :failsafe_value, :terminate_after_value, :timeout_value, :offset_value, :limit_value, :scroll_args, :source_value, :preference_value, :search_type_value, - :routing_value, :track_total_hits_value, :explain_value, :http_timeout_value + :routing_value, :track_total_hits_value, :explain_value ].each do |name| criteria.send(:"#{name}=", other.send(name)) unless other.send(name).nil? end [ @@ -147,26 +146,10 @@ fresh.tap do |criteria| criteria.timeout_value = value end end - # Specifies a http timeout, such that a SearchFlip::TimeoutError will be - # thrown when the request times out. - # - # @example - # ProductIndex.http_timeout(3).search("hello world") - # - # @param value [Fixnum] The timeout value - # - # @return [SearchFlip::Criteria] A newly created extended criteria - - def http_timeout(value) - fresh.tap do |criteria| - criteria.http_timeout_value = value - end - end - # Specifies early query termination, such that the processing will be # stopped after the specified number of results has been accumulated. # # @example # ProductIndex.terminate_after(10_000).search("hello world") @@ -345,19 +328,14 @@ def delete(params = {}) dupped_request = request.dup dupped_request.delete(:from) dupped_request.delete(:size) - http_request = connection.http_client - http_request = http_request.timeout(http_timeout_value) if http_timeout_value - - if connection.distribution || connection.version.to_i >= 5 - url = connection.distribution.nil? && connection.version.to_i < 8 ? target.type_url : target.index_url - - http_request.post("#{url}/_delete_by_query", params: request_params.merge(params), json: dupped_request) + if connection.version.to_i >= 5 + connection.http_client.post("#{target.type_url}/_delete_by_query", params: request_params.merge(params), json: dupped_request) else - http_request.delete("#{target.type_url}/_query", params: request_params.merge(params), json: dupped_request) + connection.http_client.delete("#{target.type_url}/_query", params: request_params.merge(params), json: dupped_request) end target.refresh if SearchFlip::Config[:auto_refresh] true @@ -521,12 +499,12 @@ end end end # Executes the search request for the current criteria, ie sends the - # request to Elasticsearch and returns the response. Connection, timeout - # and response errors will be rescued if you specify the criteria to be + # request to Elasticsearch and returns the response. Connection and + # response errors will be rescued if you specify the criteria to be # #failsafe, such that an empty response is returned instead. # # @example # response = CommentIndex.search("hello world").execute # @@ -610,34 +588,29 @@ private def execute! http_request = connection.http_client.headers(accept: "application/json") - http_request = http_request.timeout(http_timeout_value) if http_timeout_value http_response = if scroll_args && scroll_args[:id] http_request.post( "#{connection.base_url}/_search/scroll", params: request_params, json: { scroll: scroll_args[:timeout], scroll_id: scroll_args[:id] } ) elsif scroll_args - url = connection.distribution.nil? && connection.version.to_i < 8 ? target.type_url : target.index_url - http_request.post( - "#{url}/_search", + "#{target.type_url}/_search", params: request_params.merge(scroll: scroll_args[:timeout]), json: request ) else - url = connection.distribution.nil? && connection.version.to_i < 8 ? target.type_url : target.index_url - - http_request.post("#{url}/_search", params: request_params, json: request) + http_request.post("#{target.type_url}/_search", params: request_params, json: request) end SearchFlip::Response.new(self, SearchFlip::JSON.parse(http_response.to_s)) - rescue SearchFlip::ConnectionError, SearchFlip::TimeoutError, SearchFlip::ResponseError => e + rescue SearchFlip::ConnectionError, SearchFlip::ResponseError => e raise e unless failsafe_value SearchFlip::Response.new(self, "took" => 0, "hits" => { "total" => 0, "hits" => [] }) end