I seem to be getting some behaviour thats unexpected (for me anyway)
when using find_by_contents on an ActiveRecord? has_many association. The
results that are returned are only the records that belong to the model
returned, but the total_hits that are being returned appear to be for
the whole table.
e.g.
class Book < AR::Base
has_many :pages
end
class Page < AR::Base
belongs_to :book
acts_as_ferret :fields => [:content]
end
b1 = Book.create(:title => "Book One")
b1.page.add(:content => "The cat sat on the mat.")
b1.page.add(:content => "The cat went for a walk in the country.")
b2 = Book.create(:title => "Book Two")
b2.page.add(:content => "Once upon a time in a country quite far away.")
b2.page.add(:content => "There lived a man with his cat.")
results = b1.pages.find_by_content("cat)
results.total_hits #=> 3
results.results.length #=> 2
b1.pages.total_hits #=> 3
JK suggested following workaround on Ruby Forum:
Page.find_by_contents(query, {}, { :conditions => ["book_id=?", book.id] })