Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Commit

Permalink
[FIX] Fixed incorrect passing of options in the date and terms fa…
Browse files Browse the repository at this point in the history
…cets

Closes #116.
  • Loading branch information
karmi committed Oct 19, 2011
1 parent 152372f commit d1f89e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tire/search/facet.rb
Expand Up @@ -17,13 +17,13 @@ def initialize(name, options={}, &block)
def terms(field, options={})
size = options.delete(:size) || 10
all_terms = options.delete(:all_terms) || false
@value = { :terms => { :field => field, :size => size, :all_terms => all_terms } }.update(options)
@value = { :terms => { :field => field, :size => size, :all_terms => all_terms }.update(options) }
self
end

def date(field, options={})
interval = options.delete(:interval) || 'day'
@value = { :date_histogram => { :field => field, :interval => interval } }.update(options)
@value = { :date_histogram => { :field => field, :interval => interval }.update(options) }
self
end

Expand Down
11 changes: 11 additions & 0 deletions test/unit/search_facet_test.rb
Expand Up @@ -46,6 +46,11 @@ class FacetTest < Test::Unit::TestCase
assert_equal true, Facet.new('foo') { terms :foo, :all_terms => true }.to_hash['foo'][:terms][:all_terms]
end

should "encode custom options" do
assert_equal( { :foo => { :terms => {:field=>'bar',:size=>5,:all_terms=>false,:exclude=>['moo']} } }.to_json,
Facet.new('foo').terms(:bar, :size => 5, :exclude => ['moo']).to_json )
end

end

context "date histogram" do
Expand All @@ -60,6 +65,12 @@ class FacetTest < Test::Unit::TestCase
assert_equal({ :date => { :date_histogram => { :field => 'published_on', :interval => 'month' } } }.to_json, f.to_json)
end

should "encode custom options" do
f = Facet.new('date') { date :published_on, :value_field => 'price' }
assert_equal( {:date=>{:date_histogram=>{:field=>'published_on',:interval=>'day',:value_field=>'price' } } }.to_json,
f.to_json )
end

end

context "range facet" do
Expand Down

0 comments on commit d1f89e6

Please sign in to comment.