Skip to content

Commit

Permalink
[karmi#472] Added support for loading partial fields
Browse files Browse the repository at this point in the history
  • Loading branch information
uriagassi authored and karmi committed Oct 23, 2012
1 parent 7d834af commit 1c16b68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/tire/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def fields(*fields)
@fields = Array(fields.flatten)
self
end

def partial_field(name, options)
@partial_fields ||= {}
@partial_fields[name] = options
end

def explain(value)
@explain = value
Expand Down Expand Up @@ -156,6 +161,7 @@ def to_hash
request.update( { :size => @size } ) if @size
request.update( { :from => @from } ) if @from
request.update( { :fields => @fields } ) if @fields
request.update( { :partial_fields => @partial_fields } ) if @partial_fields
request.update( { :script_fields => @script_fields } ) if @script_fields
request.update( { :version => @version } ) if @version
request.update( { :explain => @explain } ) if @explain
Expand Down
13 changes: 13 additions & 0 deletions test/unit/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,19 @@ def foo; 'bar'; end
end
end

context "with partial fields" do

should "add partial_fields config" do
s = Search::Search.new('index') do
partial_field 'name', :include => 'name_*'
end

hash = MultiJson.decode( s.to_json )
assert_equal({'name' => { 'include' => 'name_*'} }, hash['partial_fields'])
end

end

context "explain" do

should "default to false" do
Expand Down

0 comments on commit 1c16b68

Please sign in to comment.