Skip to content

Commit

Permalink
fixed problem with current page when no records were found
Browse files Browse the repository at this point in the history
  • Loading branch information
dcrec1 committed May 24, 2010
1 parent dc5853a commit c7d447e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/acts_as_solr/parser_methods.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def parse_results(solr_data, options = {})
} }
results.update(:spellcheck => solr_data.data['spellcheck']) unless solr_data.nil? results.update(:spellcheck => solr_data.data['spellcheck']) unless solr_data.nil?
results.update(:facets => {'facet_fields' => []}) if options[:facets] results.update(:facets => {'facet_fields' => []}) if options[:facets]
unless solr_data.header['params'].nil?
header = solr_data.header
results.update :rows => header['params']['rows']
results.update :start => header['params']['start']
end
return SearchResults.new(results) if (solr_data.nil? || solr_data.total_hits == 0) return SearchResults.new(results) if (solr_data.nil? || solr_data.total_hits == 0)


configuration.update(options) if options.is_a?(Hash) configuration.update(options) if options.is_a?(Hash)
Expand All @@ -141,11 +146,6 @@ def parse_results(solr_data, options = {})
results.update(:facets => solr_data.data['facet_counts']) if options[:facets] results.update(:facets => solr_data.data['facet_counts']) if options[:facets]
results.update({:docs => result, :total => solr_data.total_hits, :max_score => solr_data.max_score, :query_time => solr_data.data['responseHeader']['QTime']}) results.update({:docs => result, :total => solr_data.total_hits, :max_score => solr_data.max_score, :query_time => solr_data.data['responseHeader']['QTime']})
results.update({:highlights=>highlighted}) results.update({:highlights=>highlighted})
unless solr_data.header['params'].nil?
header = solr_data.header
results.update :rows => header['params']['rows']
results.update :start => header['params']['start']
end
SearchResults.new(results) SearchResults.new(results)
end end


Expand Down
4 changes: 4 additions & 0 deletions test/functional/acts_as_solr_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -486,4 +486,8 @@ def test_current_page_is_returned
def test_current_page_1_is_returned def test_current_page_1_is_returned
assert_equal 1, Posting.search("test").current_page assert_equal 1, Posting.search("test").current_page
end end

def test_current_page_1_is_returned_when_no_records_found
assert_equal 1, Posting.search("nothing").current_page
end
end end

0 comments on commit c7d447e

Please sign in to comment.