Forum: Ferret Count_by_content ??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4d970cd64b30776abd944168c75d8223?d=identicon&s=25 Richard (Guest)
on 2007-06-20 18:19
Is there a count_by_content alternative to the find_by_content action?

This is because I'm wanting to do the following in my pagination method:

def list
    # step 1: set the variables you'll need
    page = (params[:page] ||= 1).to_i
    items_per_page = 20
    offset = (page - 1) * items_per_page

    # step 2: instead of performing a find, just get a count
    item_count = Item.count_with_some_custom_method()

    # step 3: create a Paginator, the second argument has to be the
number of ALL items on all pages
    @item_pages = Paginator.new(self, item_count, items_per_page, page)

    # step 4: only find the requested subset of @items
    @items = Item.find_with_some_custom_method(items_per_page, offset)
end
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2007-06-20 21:46
(Received via mailing list)
On Wed, Jun 20, 2007 at 06:19:42PM +0200, Richard wrote:
> Is there a count_by_content alternative to the find_by_content action?

there is a method total_hits you can call, but this is not really
necessary. just use find_by_contents with the :limit and :offset
options and call total_hits on the result returned to find out the total
number of results.

Jens

>     item_count = Item.count_with_some_custom_method()
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ferret-talk mailing list
> Ferret-talk@rubyforge.org
> http://rubyforge.org/mailman/listinfo/ferret-talk
>

--
Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
kraemer@webit.de | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
This topic is locked and can not be replied to.