On Wed, Oct 03, 2007 at 12:07:53PM +0100, John Leach wrote:
> Hi Cass,
> 
> I think this is a bug in acts_as_ferret.  On line 163 in
> class_methods.rb the limit variable is used but hasn't been initialised:
> 
> http://projects.jkraemer.net/acts_as_ferret/browser/trunk/plugin/acts_as_ferret/lib/class_methods.rb
> 
> In the mean time, aaf actually has paging support in there and that
> looks like it should work fine.
> 
> So instead of using :limit and :offset in your options for
> find_by_contents, drop all your page number calculations and
> use :per_page and :page.  Aaf will then figure out the limit and offset
> for you.

exactly. Use the latest trunk of the plugin, and use the
find_with_ferret method with the :multi option instead of multi_search:

Model.find_with_ferret query, :page => params[:page], :per_page => 10, :multi 
=> [ Model2, Model3 ]


cheers,
Jens


> 
> John.
> -- 
> http://www.brightbox.co.uk - UK Ruby on Rails Hosting
> 
> On Wed, 2007-10-03 at 12:52 +0200, Cass Amino wrote:
> > Hi,
> > 
> > am using this wonderful plugin acts_as_ferret and according to the
> > tutorial at http://railsenvy.com/2007/2/19/acts-as- … rial#basic
> > 
> > I worked it out except the pagination feature.
> > 
> > If I have 12 records and I give limit to 10, its correctly displaying 10
> > records in the first page and is giving the link to the second page too.
> > But when I go to the next page I find the same 10 records instead of the
> > next 2 records. Also the result count is showing only 10 instead of 12
> > thats the right count.
> > 
> > 
> > Here's my code:
> > 
> > Controller:
> > 
> > def search
> >       @users = User.available_users
> >       @user = User.find(session[:user_id])
> >   @query = params[:query] || ''
> > @total, @user_profiles = UserProfile.multi_search(@query, [ WorkProfile,
> > SchoolProfile ], :page => (params[:page]||1))
> >   @pages = pages_for(@total)
> >   unless @query.blank?
> >   @results = UserProfile.find_by_contents @query
> >   end
> > end
> > 
> > 
> > 
> > model:
> > 
> > def self.multi_search(q, additional_models = [], options = {})
> >    return nil if q.nil? or q==""
> >    default_options = {:limit => 1, :page => 1}
> >    options = default_options.merge options
> >       # get the offset based on what page we're on
> >    options[:offset] = options[:limit] * (options.delete(:page).to_i-1)
> >       # now do the query with our options
> >       results = UserProfile.find_by_contents(q, options)
> >    return [results.total_hits, results]
> > end
> 
> 
> _______________________________________________
> Ferret-talk mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/ferret-talk
-- 
Jens Krämer
http://www.jkraemer.net/ - Blog
http://www.omdb.org/     - The new free film database
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to