Skip to content

Commit

Permalink
Support changing indices for query
Browse files Browse the repository at this point in the history
  • Loading branch information
cyu committed Jun 20, 2018
1 parent f9c02dd commit a1fb13f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/chewy/search/query_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ def initialize(parameter_name, request)
def minimum_should_match(value)
@request.send(:modify, @parameter_name) { minimum_should_match(value) }
end

# Executes {Chewy::Search::Request#index} in the scope of newly created
# request object.
# @see Chewy::Search::Request#index
# @param indicies [Array<String>]
# @return [Chewy::Search::Request]
def index(*indices)
@request.index(*indices)
end
end
end
end
9 changes: 8 additions & 1 deletion lib/chewy/search/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,13 @@ def except(*values)
chain { parameters.except!(values.flatten(1)) }
end

# Returns a list of indexes to fetch.
# @param indices [Array<String>]
# @return [Chewy::Search::Request] new scope
def index(*indices)
chain { (@indices ||= []).concat(indices.flatten) }
end

# @!group Additional actions

# Returns total count of hits for the request. If the request
Expand Down Expand Up @@ -973,7 +980,7 @@ def raw_offset_value
end

def index_names
@index_names ||= _indexes.map(&:index_name).uniq
@index_names ||= @indices ? @indices.uniq : _indexes.map(&:index_name).uniq
end

def type_names
Expand Down

0 comments on commit a1fb13f

Please sign in to comment.