Skip to content

Commit

Permalink
Added @search.results.max_score
Browse files Browse the repository at this point in the history
Closes karmi#428.
  • Loading branch information
karmi committed Oct 18, 2012
1 parent 6721c85 commit ac18adf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
15 changes: 8 additions & 7 deletions lib/tire/results/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ class Collection
include Enumerable
include Pagination

attr_reader :time, :total, :options, :facets
attr_reader :time, :total, :options, :facets, :max_score

def initialize(response, options={})
@response = response
@options = options
@time = response['took'].to_i
@total = response['hits']['total'].to_i
@facets = response['facets']
@wrapper = options[:wrapper] || Configuration.wrapper
@response = response
@options = options
@time = response['took'].to_i
@total = response['hits']['total'].to_i
@facets = response['facets']
@max_score = response['hits']['max_score'].to_f
@wrapper = options[:wrapper] || Configuration.wrapper
end

def results
Expand Down
1 change: 1 addition & 0 deletions test/integration/custom_score_queries_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class CustomScoreQueriesIntegrationTest < Test::Unit::TestCase
assert_equal 2, s.results.size
assert_equal ['Three', 'Two'], s.results.map(&:title)

assert_equal 5.0, s.results.max_score
assert_equal 5.0, s.results[0]._score
assert_equal 3.0, s.results[1]._score
end
Expand Down
8 changes: 7 additions & 1 deletion test/unit/results_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class ResultsCollectionTest < Test::Unit::TestCase
Configuration.reset
@default_response = { 'hits' => { 'hits' => [{'_id' => 1, '_score' => 1, '_source' => {:title => 'Test'}},
{'_id' => 2},
{'_id' => 3}] } }
{'_id' => 3}],
'max_score' => 1.0 } }
end

should "be iterable" do
Expand Down Expand Up @@ -64,6 +65,11 @@ class ResultsCollectionTest < Test::Unit::TestCase
end
end

should "have max_score" do
collection = Results::Collection.new(@default_response)
assert_equal 1.0, collection.max_score
end

context "wrapping results" do

setup do
Expand Down

0 comments on commit ac18adf

Please sign in to comment.