lib/search_flip/criteria.rb in search_flip-2.0.0.beta vs lib/search_flip/criteria.rb in search_flip-2.0.0.beta2
- old
+ new
@@ -58,11 +58,11 @@
criteria.filter_values = (criteria.filter_values || []) + other.filter_values if other.filter_values
criteria.post_search_values = (criteria.post_search_values || []) + other.post_search_values if other.post_search_values
criteria.post_must_values = (criteria.post_must_values || []) + other.post_must_values if other.post_must_values
criteria.post_must_not_values = (criteria.post_must_not_values || []) + other.post_must_not_values if other.post_must_not_values
criteria.post_should_values = (criteria.post_should_values || []) + other.post_should_values if other.post_should_values
- criteria.post_filter_values = (criteria.post_filter_vales || []) + other.post_filter_values if other.post_filter_values
+ criteria.post_filter_values = (criteria.post_filter_values || []) + other.post_filter_values if other.post_filter_values
criteria.aggregation_values = (criteria.aggregation_values || {}).merge(other.aggregation_values) if other.aggregation_values
criteria.terminate_after_value = other.terminate_after_value unless other.terminate_after_value.nil?
criteria.timeout_value = other.timeout_value unless other.timeout_value.nil?
end
end
@@ -147,10 +147,26 @@
attributes.each do |key, value|
send "#{key}=", value
end
end
+ # Allows to set query specific settings like e.g. connection and index
+ # name. Please note, however, that this should only be used for special
+ # cases and the subsequent query can not be serialized. Checkout
+ # SearchFlip::Index.with_settings for more details.
+ #
+ # @example
+ # UserIndex.where("...").with_settings(connection: ProxyConnection)
+ #
+ # @return [SearchFlip::Criteria] Simply returns self
+
+ def with_settings(*args)
+ fresh.tap do |criteria|
+ criteria.target = target.with_settings(*args)
+ end
+ end
+
# Generates the request object from the attributes specified via chaining,
# like eg offset, limit, query, filters, aggregations, etc and returns a
# Hash that later gets serialized as JSON.
#
# @return [Hash] The generated request object
@@ -660,41 +676,38 @@
# Executes the search request for the current criteria, ie sends the
# 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.
#
- # @param connection An optional alternative connection to used to send the
- # request to for e.g. proxying
- #
# @example
# response = CommentIndex.search("hello world").execute
#
# @return [SearchFlip::Response] The response object
- def execute(connection: target.connection)
+ def execute
@response ||= begin
http_request = SearchFlip::HTTPClient.headers(accept: "application/json")
http_response =
if scroll_args && scroll_args[:id]
if target.connection.version.to_i >= 2
http_request.post(
- "#{connection.base_url}/_search/scroll",
+ "#{target.connection.base_url}/_search/scroll",
json: { scroll: scroll_args[:timeout], scroll_id: scroll_args[:id] }
)
else
http_request
.headers(content_type: "text/plain")
- .post("#{connection.base_url}/_search/scroll", params: { scroll: scroll_args[:timeout] }, body: scroll_args[:id])
+ .post("#{target.connection.base_url}/_search/scroll", params: { scroll: scroll_args[:timeout] }, body: scroll_args[:id])
end
elsif scroll_args
http_request.post(
- "#{target.type_url(connection: connection)}/_search",
+ "#{target.type_url}/_search",
params: { scroll: scroll_args[:timeout] },
json: request
)
else
- http_request.post("#{target.type_url(connection: connection)}/_search", json: request)
+ http_request.post("#{target.type_url}/_search", json: request)
end
SearchFlip::Response.new(self, http_response.parse)
rescue SearchFlip::ConnectionError, SearchFlip::ResponseError => e
raise e unless failsafe_value