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

Commit

Permalink
Fixed total_entries method when the index has no data.
Browse files Browse the repository at this point in the history
  • Loading branch information
aassarattanakul committed Nov 25, 2009
1 parent 4c0e214 commit d3757ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/thinking_sphinx/search.rb
Expand Up @@ -168,6 +168,8 @@ def total_pages
#
def total_entries
populate
return 0 if @results[:total_found].nil?

@total_entries ||= @results[:total_found]
end

Expand Down
8 changes: 8 additions & 0 deletions spec/lib/thinking_sphinx/search_spec.rb
Expand Up @@ -868,6 +868,14 @@
it "should return the total number of results, not just the amount on the page" do
ThinkingSphinx::Search.new.total_entries.should == 41
end

it "should return 0 if there is no index and therefore no results" do
@client.stub!(:query => {
:matches => [], :total_found => nil
})

ThinkingSphinx::Search.new.total_entries.should == 0
end
end

describe '#offset' do
Expand Down

0 comments on commit d3757ca

Please sign in to comment.