I don’t know if this is a bug, or wanted behavior, but for me it was a
pain in… So here’s the problem + a bugfix.
Lets say you have a model “Article” with the following fields: title,
visible - and these records
title, visible
ferret talk, 1
ruby talk, 0
ruby on rails, 1
lets talk about ruby, 1
If I let Article act as a ferret, and do:
result = Article.find_by_content(‘ruby’)
Result will contain 3 items and “total_hits” will return 3
However, if I add a condition:
result = Article.find_by_content(‘ruby’, {}, ‘visible = 1’)
Result will contain 2 items - which is correct
But “hotal_hits” will still return 3 - not what I would expect.
Fix for this:
-
In the acts_as_ferret plugin, find the file class_methods.rb
-
Go to line 276 where you have this code-block
if results.any?
conditions = combine_conditions([ "#{table_name}.#{primary_key} in
(?)", results.keys ],
find_options[:conditions])
result = self.find(:all,
find_options.merge(:conditions => conditions))
end
and add this line:
if results.any?
conditions = combine_conditions([ "#{table_name}.#{primary_key} in
(?)", results.keys ],
find_options[:conditions])
result = self.find(:all,
find_options.merge(:conditions => conditions))
total_hits = result.length <===== ADD THIS!!!
end
- Carsten