Skip to content

Commit

Permalink
Adding AllowPartialSearchResults parameter
Browse files Browse the repository at this point in the history
Just adding this for completeness. I didn't really test using this so
you can definitely remove this if it's not wanted. This support was
added in ES 6.3.

https://www.elastic.co/blog/this-week-in-elasticsearch-and-apache-lucene-2018-02-05
  • Loading branch information
mattzollinhofer committed Aug 26, 2018
1 parent 63515c9 commit af46a81
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chewy/search/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Search
# @see Chewy::Search::Request#parameters
# @see Chewy::Search::Parameters::Storage
class Parameters
QUERY_STRING_PARAMS = %i[search_type request_cache].freeze
QUERY_STRING_PARAMS = %i[search_type request_cache allow_partial_search_results].freeze
# Default storage classes warehouse. It is probably possible to
# add your own classes here if necessary, but I'm not sure it will work.
#
Expand Down
27 changes: 27 additions & 0 deletions lib/chewy/search/parameters/allow_partial_search_results.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'chewy/search/parameters/storage'

module Chewy
module Search
class Parameters
# Stores boolean value, but has 3 states: `true`, `false` and `nil`.
#
# @see Chewy::Search::Request#allow_partial_search_results
# @see https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-request-body.html#_parameters_4
class AllowPartialSearchResults < Storage
# We don't want to render `nil`, but render `true` and `false` values.
#
# @see Chewy::Search::Parameters::Storage#render
# @return [{Symbol => Object}, nil]
def render
{self.class.param_name => value} unless value.nil?
end

private

def normalize(value)
!!value unless value.nil?
end
end
end
end
end
5 changes: 5 additions & 0 deletions spec/chewy/search/parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def storage_object_ids(params)
specify { expect(subject.render).to eq(search_type: 'query_then_fetch') }
end

context do
subject { described_class.new(allow_partial_search_results: true) }
specify { expect(subject.render).to eq(allow_partial_search_results: true) }
end

context do
subject { described_class.new(query: {foo: 'bar'}, filter: {moo: 'baz'}) }
specify { expect(subject.render).to eq(body: {query: {bool: {must: {foo: 'bar'}, filter: {moo: 'baz'}}}}) }
Expand Down

0 comments on commit af46a81

Please sign in to comment.