<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>opensoul.org - acts_as_ferret will_paginate Comments</title>
  <id>tag:opensoul.org,2010:/2007/8/17/acts_as_ferret-will_paginate/comments</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate/comments.xml" rel="self" type="application/atom+xml"/>
  <link href="/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
  <updated>2010-06-08T13:14:30Z</updated>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>David Lynch</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:21925</id>
    <published>2010-06-08T13:14:30Z</published>
    <updated>2010-06-08T13:14:30Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by David Lynch</title>
<content type="html">&lt;p&gt;Hi Lucas,&lt;/p&gt;


	&lt;p&gt;I am using acts_as_version 0.4.4 and will_paginate 2.3.11, I have some what same code in my 
controller
@ads = Ad.find_with_ferret(params[:q]+&#8221;~&#8221;, :page =&amp;gt; params[&#8216;page&#8217;], :per_page =&amp;gt; 10)&lt;/p&gt;


	&lt;p&gt;view
will_paginate @ads&lt;/p&gt;


	&lt;p&gt;But i only get one page of paginated ads can&#8217;t go second page just get nil results even do I know there is more that 10 result.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Lucas Renan</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:21822</id>
    <published>2010-05-26T19:38:13Z</published>
    <updated>2010-05-26T19:38:13Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Lucas Renan</title>
<content type="html">&lt;p&gt;I tried to do a pagination with acts_as_ferret version 0.4.4 and will_paginate version 2.3.1.
I just did:&lt;/p&gt;


controller
&lt;pre&gt;
@data = Model.find_with_ferret(params[&quot;q&quot;]+&quot;~&quot;, :page =&amp;gt; params['page'], :per_page =&amp;gt; 10)
&lt;/pre&gt;

view
&lt;pre&gt;
&amp;lt;%= will_paginate @data %&amp;gt;
&lt;/pre&gt;

	&lt;p&gt;and it seems work fine this way&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Fasal</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:12725</id>
    <published>2009-04-21T07:03:58Z</published>
    <updated>2009-04-21T07:03:58Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Fasal</title>
<content type="html">&lt;p&gt;hiii Alderete
Thanks for your own question with self answer.I had the same kind of error and i put your code to enviornment.rb and that fixed the problem.Thanks once again for the answer.Have a great day.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Alderete</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:8471</id>
    <published>2008-10-01T03:29:51Z</published>
    <updated>2008-10-01T03:29:51Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Alderete</title>
<content type="html">&lt;p&gt;Let me answer my own question with what I finally figured out. Although I&#8217;m using the supposedly current 0.4.3 gem of acts_as_ferret, the &lt;a href=&quot;http://projects.jkraemer.net/rdoc/acts_as_ferret/classes/ActsAsFerret/SearchResults.html&quot;&gt;documentation for acts_as_ferret&lt;/a&gt; asserts that total_hits is aliased to total_entries.&lt;/p&gt;


	&lt;p&gt;Maybe that&#8217;s true in a more recent version of acts_as_ferret, but for my application, I had to add the following:&lt;/p&gt;


&lt;pre&gt;
module ActsAsFerret
  class SearchResults
    def total_entries
      @total_hits
    end
  end
end
&lt;/pre&gt;

	&lt;p&gt;(I added it to an initializer, but you can add it almost anywhere and just require it in.)&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Alderete</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:8468</id>
    <published>2008-10-01T03:02:51Z</published>
    <updated>2008-10-01T03:02:51Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Alderete</title>
<content type="html">&lt;p&gt;As Joakim writes, the latest versions of acts_as_ferret and will_paginate seem to work together for the basic pagination. But will_paginate includes another view helper method, e.g. &amp;lt;%= page_entries_info @people %&amp;gt;, to show the &#8220;showing xx-yy of zz&#8221; information, which is a nice supplement to the basic paging controls.&lt;/p&gt;


	&lt;p&gt;But, using this helper throws an exception &#8220;undefined method `total_entries&#8217; for #&#8221;. Anyone have any ideas how to patch around this?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Joakim</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:6522</id>
    <published>2008-06-17T15:08:17Z</published>
    <updated>2008-06-17T15:08:17Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Joakim</title>
<content type="html">&lt;p&gt;Actually, you don&#8217;t need any special code to do this.&lt;/p&gt;


	&lt;p&gt;At least the latest stable versions of acts_as_ferret (I&#8217;m using Rails 2.1) is fully compatible with will_paginate. Just use:&lt;/p&gt;


	&lt;p&gt;@products = Product.find_with_ferret(params[:q], {:page =&amp;gt; params[:page], :per_page =&amp;gt; 50}, find_options)
(where find_options is a hash with parameters you&#8217;d normally send to ActiveRecord::Base.find*, like :order, :conditions, :include, etc.)&lt;/p&gt;


	&lt;p&gt;Then just use &amp;lt;%= will_paginate @products %&amp;gt; like you normally would.&lt;/p&gt;


	&lt;p&gt;This is actually documented in the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; docs for acts_as_ferret&#8230;&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Avishai</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:6475</id>
    <published>2008-06-13T20:37:10Z</published>
    <updated>2008-06-13T20:37:10Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Avishai</title>
<content type="html">&lt;p&gt;Awesome! I dropped the code into lib/acts_as_ferret_extension.rb and required it in environment.rb &lt;del&gt;- works very nicely, thanks :&lt;/del&gt;)&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Santiago</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:6034</id>
    <published>2008-05-09T05:37:54Z</published>
    <updated>2008-05-09T05:37:54Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Santiago</title>
<content type="html">&lt;p&gt;I put the code in lib/ferret.rb, then require &#8216;lib/ferret&#8217; in environment.rb, after doing that I got the error below.&lt;/p&gt;


	&lt;p&gt;Removing the file back from lib solves the problem. What am I doing wrong? :(&lt;/p&gt;


	&lt;p&gt;Loading development environment (Rails 2.0.2)
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:263:in `load_missing_constant&#8217;:NameError: uninitialized constant Ferret::Analysis::Analyzer&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>izit</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:5768</id>
    <published>2008-04-19T18:20:10Z</published>
    <updated>2008-04-19T18:20:10Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by izit</title>
<content type="html">&lt;p&gt;Hi,&lt;/p&gt;


	&lt;p&gt;I am having some issues with this lib.&lt;/p&gt;


	&lt;p&gt;in  my controller I use:&lt;/p&gt;


	&lt;p&gt;@mutations = Mutation.paginate_search(&#8220;test&#8221;,{:page=&amp;gt;1})&lt;/p&gt;


	&lt;p&gt;if I use @mutations in a render_partial in my view:&lt;/p&gt;


	&lt;p&gt;&amp;lt;%= render :partial =&amp;gt; @mutations %&amp;gt;&lt;/p&gt;


	&lt;p&gt;I get the following error message:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;ActiveRecord::DangerousAttributeError in Mutations#list&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;Showing mutations/_mutation.rhtml where line #4 raised:&lt;/p&gt;


	&lt;p&gt;hash is defined by ActiveRecord&lt;/p&gt;


	&lt;p&gt;I have debugged this down to a problem that ActiveRecord does not see @mutations as an array.&lt;/p&gt;


	&lt;p&gt;If I do Mutations.find_with_ferret or Mutations.paginate I do not get the error. It only happens with function in the lib provided here. I use lates &lt;span class=&quot;caps&quot;&gt;AAF&lt;/span&gt; (trunk) and will_paginate (2.2.1)&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Adam</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:5617</id>
    <published>2008-03-29T03:44:20Z</published>
    <updated>2008-03-29T03:44:20Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Adam</title>
<content type="html">&lt;p&gt;Just confirming that aiwilliams was correct&#8230; Also, I noticed the syntax has changed for those of you who are using the latest version of &lt;span class=&quot;caps&quot;&gt;AAF&lt;/span&gt;. Here is a sample to search across models and paginate (remember to use :store_class_name =&amp;gt; true):&lt;/p&gt;


&lt;pre&gt;@results = ActsAsFerret::find(params[:q], [ModelA, ModelB, ModelC], {:page =&amp;gt; params[:page], :per_page =&amp;gt; 25})&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Adam</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:5611</id>
    <published>2008-03-27T09:56:22Z</published>
    <updated>2008-03-27T09:56:22Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Adam</title>
<content type="html">&lt;p&gt;Hi &#8211; great work Brandon.&lt;/p&gt;


	&lt;p&gt;I want to search across about 10 models on one search page.&lt;/p&gt;


I saw a post by Jens: http://www.ruby-forum.com/topic/126739#565176 to use the :multi option with find_with_ferret and changed the lib file accordingly:
&lt;pre&gt;module ActsAsFerret
  module ClassMethods
    def paginate_search(query, options = {})
      page, per_page, total = wp_parse_options(options)
      pager = WillPaginate::Collection.new(page, per_page, total)
      options.merge!(:offset =&amp;gt; pager.offset, :limit =&amp;gt; per_page)
      result = find_with_ferret(query, options)
      returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |pager|
        pager.replace result
      end
    end
  end
end
&lt;/pre&gt;

And this from my search controller&#8230;. but it only searches Model1:
&lt;pre&gt;
@results = Model1.paginate_search @query, 
           :page =&amp;gt; @page, :per_page =&amp;gt; @per_page, 
           :multi =&amp;gt; [Model2, Model3, Model4]
&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Behrang</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:5437</id>
    <published>2008-03-12T12:10:15Z</published>
    <updated>2008-03-12T12:10:15Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Behrang</title>
<content type="html">There has been a change in the latest version of WillPaginate here is the code that is working for me:
&lt;pre&gt;
module ActsAsFerret
  module ClassMethods
    def paginate_search(query, options = {})
      page, per_page, total = wp_parse_options(options)
      pager = WillPaginate::Collection.new(page, per_page, total)
      options.merge!(:offset =&amp;gt; pager.offset, :limit =&amp;gt; per_page)
      result = find_by_contents(query, options)
      returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |pager|
        pager.replace result
      end
    end
  end
end
&amp;lt;/p&amp;gt;
Cheers</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4899</id>
    <published>2008-01-02T23:33:09Z</published>
    <updated>2008-01-02T23:33:09Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;aiwilliams,&lt;/p&gt;


	&lt;p&gt;Thanks for pointing that out.  I haven&#8217;t tried it, but looking at the code, you appear to be correct.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>aiwilliams</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4896</id>
    <published>2008-01-02T22:03:33Z</published>
    <updated>2008-01-02T22:03:33Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by aiwilliams</title>
<content type="html">&lt;p&gt;Is any of this necessary for the latest acts_as_ferret? find_by_contents&#8217; second argument, the options, can include :page and :per_page, and the SearchResults returned from it has the appropriate extensions to work with the will_paginate view method.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Mike D</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4845</id>
    <published>2007-12-26T16:55:39Z</published>
    <updated>2007-12-26T16:55:39Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Mike D</title>
<content type="html">&lt;p&gt;Anyone know how to do this pagination when you&#8217;re doing ferret searches from &amp;gt;1 model?  Can&#8217;t seem to get it to work!  Thanks!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Raecoo</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4511</id>
    <published>2007-12-11T12:50:34Z</published>
    <updated>2007-12-11T12:50:34Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Raecoo</title>
<content type="html">&lt;p&gt;it&#8217;s works in my apps is fine.
&lt;strong&gt;Nice&lt;/strong&gt;,Thank you,Brandon&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brad Carson</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4424</id>
    <published>2007-12-08T03:31:31Z</published>
    <updated>2007-12-08T03:31:31Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brad Carson</title>
<content type="html">&lt;p&gt;Awesome!  Works great!  Thank you, Brandon!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Frederico Araujo</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4414</id>
    <published>2007-12-07T14:41:35Z</published>
    <updated>2007-12-07T14:41:35Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Frederico Araujo</title>
<content type="html">&lt;p&gt;I wrote a basic way to get will_paginate to work with ferret
http://www.frederico-araujo.com/2007/12/7/search-with-ferret-using-will_paginate&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Johnny</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4402</id>
    <published>2007-12-07T01:36:33Z</published>
    <updated>2007-12-07T01:36:33Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Johnny</title>
<content type="html">&lt;p&gt;Hey man &#8211; thanks for a great piece of code.  Works like a charm.
Cheers, JR&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>jags</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4169</id>
    <published>2007-11-16T06:34:21Z</published>
    <updated>2007-11-16T06:34:21Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by jags</title>
<content type="html">&lt;p&gt;hi brandon&lt;/p&gt;


	&lt;p&gt;can you pls check on my comment above.&lt;/p&gt;


	&lt;p&gt;how can i get the total_hits i.e the total no of results found for the search so that it can be displayed on the rhtml&lt;/p&gt;


	&lt;p&gt;pls help
thanks
jags&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brendon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4153</id>
    <published>2007-11-14T21:07:54Z</published>
    <updated>2007-11-14T21:07:54Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brendon</title>
<content type="html">&lt;p&gt;Hi everyone, after a bit of working, I&#8217;ve come up with a solution to my problem, which will hopefully help those who want to do what I was doing (filtering search results after the search query has been run, then paginating them). Here&#8217;s the modified code:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
module ActsAsFerret
  module ClassMethods
    def paginate_search(query, options = {}, &#38;block)
      options, page, per_page = wp_parse_options!(options)
      options.merge!(:limit =&amp;gt; :all) 
      results = find_by_contents(query, options)
      results.delete_if { |result| yield(result) }
      returning WillPaginate::Collection.new(page, per_page, results.length) do |pager|
        pager.replace results[pager.offset..pager.offset + pager.per_page - 1]
      end
    end
  end
end
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Firstly, can someone explain the use of result = result = find_by&#8230; ? It seems a bit redundant to define the variable twice?&lt;/p&gt;


	&lt;p&gt;Anyway, basically how this works is we still parse the options etc&#8230; but instead of making find_by_contents get a page and an offset, we just get them all by defining :limit =&amp;gt; :all. Then we run delete_if and yeild back to the calling method to provide us with a true false value, then we end up with a filtered set of results. We then manually build the result set by picking the right records from the array of results.&lt;/p&gt;


	&lt;p&gt;The calling method looks like:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
    @results = Page.paginate_search(&quot;+domain_hash:\&quot;#{domain_hash}\&quot; AND #{@query}&quot;, :lazy =&amp;gt; [:name], :page =&amp;gt; params[:page], :per_page =&amp;gt; 5, :models =&amp;gt; :all){ |result|
      !result.component_instance.viewable?(user) || (result.parent.respond_to?('password') &#38;&#38; result.parent.component_instance.password(session, user))
    }
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Hope this is of some use to somebody. :)&lt;/p&gt;


	&lt;p&gt;Cheers,&lt;/p&gt;


	&lt;p&gt;Brendon&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>jags</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4150</id>
    <published>2007-11-14T09:28:05Z</published>
    <updated>2007-11-14T09:28:05Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by jags</title>
<content type="html">&lt;p&gt;hello all
i need some help.
i was earlier using paginating_find and moved on to will_paginate now&lt;/p&gt;


	&lt;p&gt;i my view i am showing the total count of the ferret search results.&lt;/p&gt;


	&lt;p&gt;Search for “book” Produced Results&lt;/p&gt;


	&lt;p&gt;i have @products.size ————which failed
i tried @products.total_hits ——failed again
i made the result variable in &lt;span class=&quot;caps&quot;&gt;AAF&lt;/span&gt; module as instance var and tried
@results.total_hits———-also failed&lt;/p&gt;


	&lt;p&gt;can anybody help me with this pls.
Jags&lt;/p&gt;


	&lt;p&gt;Everything from above worked for me
thanks a ton ……..thanks&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brendon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4144</id>
    <published>2007-11-09T01:53:21Z</published>
    <updated>2007-11-09T01:53:21Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brendon</title>
<content type="html">&lt;p&gt;Thanks Brandon (cool name :) )&lt;/p&gt;


	&lt;p&gt;That&#8217;s a good idea, unfortunately it won&#8217;t work in my situation as one of the ways we protect content is via a simple password on a folder that contains the content. If the user has visited that folder before, they will have already been asked for a password and we would have stored a session variable to that effect, and that&#8217;s the only way we&#8217;d know, so we can&#8217;t store this in the index.&lt;/p&gt;


	&lt;p&gt;Thanks for your help however, and I think I might have had an idea (though I&#8217;m not near my workstation to check it) but it goes like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
module ActsAsFerret
  module ClassMethods
    def paginate_search(query, options = {})
      options, page, per_page = wp_parse_options!(options)
      pager = WillPaginate::Collection.new(page, per_page, nil)
      options.merge!(:offset =&amp;gt; pager.offset, :limit =&amp;gt; per_page)
      result = result = find_by_contents(query, options)
      result = result.delete_if { |result|
      !result.component_instance.viewable?(user) &#38;&#38; (result.parent.respond_to?('password') &#38;&#38; result.parent.component_instance.password(session, user))
    }
#change the total_hits to something like results.length
      returning WillPaginate::Collection.new(page, per_page, result.length) do |pager|
        pager.replace result
      end
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Wait, now that I think about that, it&#8217;s quite absurd as the ferret query is automatically limited anyway :) I suppose the only way to really do it is to return all the results, filter them, then paginate from there. This shouldn&#8217;t be too expensive since the sites are quite small.&lt;/p&gt;


	&lt;p&gt;Thanks heaps :)&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4130</id>
    <published>2007-11-07T23:18:43Z</published>
    <updated>2007-11-07T23:18:43Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;Brendon,&lt;/p&gt;


	&lt;p&gt;I think your best bet would be to push the requirements for who can view the models into the index.  For example, if your model is only viewable by certain roles, add a #viewable_by method to your model that returns an array of the roles, and index this field.  Then when you search, you could only search for objects that are viewable by the current user&#8217;s roles.&lt;/p&gt;


	&lt;p&gt;Other than that, I don&#8217;t have any ideas about how you would accomplish this without breaking pagination.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brendon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:4128</id>
    <published>2007-11-07T21:06:23Z</published>
    <updated>2007-11-07T21:06:23Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brendon</title>
<content type="html">&lt;p&gt;One thing this (or any other pagination system that I could find) doesn’t take into account is whether a particular logged in user (for example) can see certain records. They will all be in the ferret database (except for those that should never be in there, which we can define in ferret_enabled? in the model) but depending on if the user is allowed to see the results, we need to remove them from the results. Previously I tried this:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
    @results.delete_if { |result|
      !result.component_instance.viewable?(user) &#38;&#38; (result.parent.respond_to?('password') &#38;&#38; result.parent.component_instance.password(session, user))
    }
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;(just a few conditions to decide whether to delete the object or not). This works well, but makes the pagination inaccurate as it removes items after the pagniator has done its magic on the find_by_contents method. A page with 5 results normally, might only show 4. If the last page had 1 result on it but this method deleted it then the page would be strangely empty etc…&lt;/p&gt;


	&lt;p&gt;Is there a way to filter the results before they’re paginated? I tried to do it inside the module but once the deleteif had run, the paginator complained that it couldn’t find total_hits in the array called result.&lt;/p&gt;


	&lt;p&gt;Your help would very much be appreciated :)&lt;/p&gt;


	&lt;p&gt;Just to clarify, the above filters aren’t able to be done via &lt;span class=&quot;caps&quot;&gt;SQL&lt;/span&gt; or anything like that. They rely on being able to have the object in the applications context.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Jd</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3786</id>
    <published>2007-09-23T21:22:32Z</published>
    <updated>2007-09-23T21:22:32Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Jd</title>
<content type="html">&lt;p&gt;I wanted to do a search, and filter it with :find_conditions. I had to modify your code a little bit to make it work.&lt;/p&gt;


	&lt;p&gt;module ActsAsFerret
  module ClassMethods
    def paginate_search(query, options = {}, find_options = {})
      options, page, per_page = wp_parse_options!(options)
      pager = WillPaginate::Collection.new(page, per_page, nil)
      options.merge!(:offset =&amp;gt; pager.offset, :limit =&amp;gt; per_page)
      result = result = find_by_contents(query, options, find_options)
      returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |pager|
        pager.replace result
      end
    end
  end
end&lt;/p&gt;


	&lt;p&gt;And, in my controller&lt;/p&gt;


	&lt;p&gt;@posts = Post.paginate_search 
params[:q], 
{:per_page =&amp;gt; 5, :page =&amp;gt; params[:page]},
{:conditions =&amp;gt; &#8220;some_condition&#8221;}&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Skyblaze</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3758</id>
    <published>2007-09-19T08:21:34Z</published>
    <updated>2007-09-19T08:21:34Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Skyblaze</title>
<content type="html">&lt;p&gt;i noticed a strange behaviour. Your modified method to use will_paginate with acts_as_ferret  worked for me perfectly then suddenly in a model the pagination doesn&#8217;t work correctly. If i put 2 as a value to the :per_page parameter (as i did before) it puts only one result per page creating 2 pages. If i put 1 as the :per_page paramter it puts 1 result per page but it creates 3 pages (for only two results) with the first page empty. On the other model(controller with exactly the same code all work perfectly. If i use the vanilla &#8220;paginate&#8221; will_paginate plugin method all work great!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>EmmanuelOga</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3686</id>
    <published>2007-09-13T20:38:10Z</published>
    <updated>2007-09-13T20:38:10Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by EmmanuelOga</title>
<content type="html">&lt;p&gt;For total compatibilitie with my previous acts_as_ferret code I added the total_hits method based on total_entries. Now it works seamlessly with all my code. Thank you very much!&lt;/p&gt;


	&lt;p&gt;module ActsAsFerret
  module ClassMethods
end&lt;/p&gt;
	&lt;pre&gt;&lt;code&gt;def paginate_search(query, options = {})
    options, page, per_page = wp_parse_options!(options)
    pager = WillPaginate::Collection.new(page, per_page, nil)
    options.merge!(:offset =&amp;gt; pager.offset, :limit =&amp;gt; per_page)
    result = result = find_by_contents(query, options)
    returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |final_pager|
      final_pager.replace result
      def final_pager.total_hits
        total_entries()
      end
    end
  end&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;end&lt;/code&gt;&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3682</id>
    <published>2007-09-13T13:32:54Z</published>
    <updated>2007-09-13T13:32:54Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;claudia: I&#8217;ll look into it.  Maybe different versions of ferret/acts_as_ferret respond differently to the offset.&lt;/p&gt;


	&lt;p&gt;Skyblaze: Sorry, but this isn&#8217;t a support forum for acts_as_ferret. Any fields that you want to search with ferret need to be declared with the &lt;code&gt;:feilds&lt;/code&gt; option to acts_as_ferret.  Please go to the acts_as_ferret site and documentation unless you have specific issues with the code in this post.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Skyblaze</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3680</id>
    <published>2007-09-13T08:18:16Z</published>
    <updated>2007-09-13T08:18:16Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Skyblaze</title>
<content type="html">&lt;p&gt;actually i&#8217;ve tried to search other fields with that form but it doesn&#8217;t work i can only search in the default field&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Skyblaze</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3679</id>
    <published>2007-09-13T08:02:58Z</published>
    <updated>2007-09-13T08:02:58Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Skyblaze</title>
<content type="html">&lt;p&gt;I tried different fields but with the user_id field it returns nothing and i don&#8217;t understand why. In my model file i don&#8217;t have the user_id field listed in &#8220;acts_as_ferret :fields =&amp;gt; [:rag_soc]&#8221; (i&#8217;ve only that rag_soc field), but that doesn&#8217;t matter right? I can then use in my search string the form &#8220;field_name:value&#8221; right? But it doesn&#8217;t work!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>claudia</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3672</id>
    <published>2007-09-12T16:11:18Z</published>
    <updated>2007-09-12T16:11:18Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by claudia</title>
<content type="html">&lt;p&gt;I had the same issue as rudionrails, with the search results paginating through the same ten results over and over again. I created an offset variable which is equal to per_page * (current_page &#8211; 1). This fixed the pagination for me, and now it works perfectly.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3671</id>
    <published>2007-09-12T15:41:10Z</published>
    <updated>2007-09-12T15:41:10Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;Skyblaze:&lt;/p&gt;


	&lt;p&gt;Does &lt;code&gt;find_by_contents&lt;/code&gt; return any results?  If not, then there&#8217;s something wrong with your acts_as_ferret configuration and you should &lt;a href=&quot;http://projects.jkraemer.net/acts_as_ferret/&quot;&gt;look to the acts_as_ferret documentation for more help&lt;/a&gt;.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Skyblaze</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3670</id>
    <published>2007-09-12T15:30:31Z</published>
    <updated>2007-09-12T15:30:31Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Skyblaze</title>
<content type="html">&lt;p&gt;Ok now it works but i have a strange problem. If i do a search on two text fields all works correctly but if i do a simple search (for the customers table) as : &#8220;user_id:1&#8221;  it returns an empty array. It seems it doesn&#8217;t want to work  only with this field! How can it be possible?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3618</id>
    <published>2007-09-06T12:36:41Z</published>
    <updated>2007-09-06T12:36:41Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;Skyblaze,&lt;/p&gt;


	&lt;p&gt;Sounds like the method above isn&#8217;t being required.  You&#8217;ll need to put a require statement in environment.rb if you put this snippet in the lib directory.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Skyblaze</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3615</id>
    <published>2007-09-06T09:10:47Z</published>
    <updated>2007-09-06T09:10:47Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Skyblaze</title>
<content type="html">&lt;p&gt;i get this error:&lt;/p&gt;


	&lt;p&gt;undefined method `find_search&#8217; for Customer:Class&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3609</id>
    <published>2007-09-05T19:49:52Z</published>
    <updated>2007-09-05T19:49:52Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;James H., I&#8217;m putting it in the lib directory for my app and requiring it in environment.rb&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>James H.</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3606</id>
    <published>2007-09-05T19:36:19Z</published>
    <updated>2007-09-05T19:36:19Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by James H.</title>
<content type="html">&lt;p&gt;Silly question, but are you dropping this code directly into your local copy of the &lt;span class=&quot;caps&quot;&gt;AAF&lt;/span&gt; plugin, or are you injecting it some how?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3531</id>
    <published>2007-08-30T22:48:19Z</published>
    <updated>2007-08-30T22:48:19Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;tarsolya,&lt;/p&gt;


	&lt;p&gt;This should support anything that &lt;code&gt;find_by_contents&lt;/code&gt; supports.  All I&#8217;m doing is wrapping that to make it compatible with find_by_contents.&lt;/p&gt;


	&lt;p&gt;You may want to be careful though with &lt;code&gt;:conditions&lt;/code&gt;, as the acts_as_ferret documentation states, because the conditions are applied to the search results from the ferret index, so your search results will most likely have fewer results that you expect &lt;code&gt;per_page&lt;/code&gt;.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>tarsolya</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3522</id>
    <published>2007-08-30T13:51:52Z</published>
    <updated>2007-08-30T13:51:52Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by tarsolya</title>
<content type="html">&lt;p&gt;I mean, conditions.&lt;/p&gt;


	&lt;p&gt;Somehow it was stripped out from my previous comment.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>tarsolya</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3521</id>
    <published>2007-08-30T13:45:57Z</published>
    <updated>2007-08-30T13:45:57Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by tarsolya</title>
<content type="html">&lt;p&gt;Brandon,&lt;/p&gt;


	&lt;p&gt;just a quick question without trying this out (forgive me please on this one), but does this support &lt;strong cite=&quot;condition&quot;&gt;s&lt;/strong&gt; on ferret&#8217;s find_by_contents?&lt;/p&gt;


	&lt;p&gt;Thanks,
András&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3518</id>
    <published>2007-08-30T11:44:42Z</published>
    <updated>2007-08-30T11:44:42Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;Tim,&lt;/p&gt;


	&lt;p&gt;The &lt;code&gt;WillPaginate::Collection&lt;/code&gt; has a &lt;code&gt;total_entries&lt;/code&gt; method, along with &lt;code&gt;current_page&lt;/code&gt;, &lt;code&gt;per_page&lt;/code&gt;.  Those should get you what you want.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Tim</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3517</id>
    <published>2007-08-30T10:30:16Z</published>
    <updated>2007-08-30T10:30:16Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Tim</title>
<content type="html">&lt;p&gt;Really like your lib and it works great except for one thing&#8230;&lt;/p&gt;


	&lt;p&gt;I seem to be getting an error when I can .total_hits &#8211; I get a WillPaginate::Collection error.  And I know that this is because now we call:&lt;/p&gt;


	&lt;p&gt;Model.paginate_search params[:search],
                                          :page =&amp;gt; params[:page],
                                          :per_page =&amp;gt; 20&lt;/p&gt;


	&lt;p&gt;In my old app, I was doing an unless .total_hits == 0 do &#8211; &#8221;.total_hits whatevers matched your query.&#8221;&lt;/p&gt;


	&lt;p&gt;I can&#8217;t seem to get another .total_hits working :( &#8211; any ideas?&lt;/p&gt;


	&lt;p&gt;Thanks.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3446</id>
    <published>2007-08-24T13:11:13Z</published>
    <updated>2007-08-24T13:11:13Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;rudionrails,&lt;/p&gt;


	&lt;p&gt;That&#8217;s not what I&#8217;m seeing.&lt;/p&gt;


&lt;pre&gt;
$ gem list ferret
ferret (0.11.4, 0.11.3)
$ script/console
&amp;gt;&amp;gt; result = Product.find_by_contents('*')
=&amp;gt; #&amp;lt;ActsAsFerret::SearchResults:0x32c97ac …&amp;gt;
&amp;gt;&amp;gt; result.size
=&amp;gt; 10
&amp;gt;&amp;gt; result.total_hits
=&amp;gt; 326
&amp;gt;&amp;gt; result = Product.find_by_contents('*', :limit =&amp;gt; 1)
=&amp;gt; #&amp;lt;ActsAsFerret::SearchResults:0x3125c20 …&amp;gt;
&amp;gt;&amp;gt; result.size
=&amp;gt; 1
&amp;gt;&amp;gt; result.total_hits
=&amp;gt; 326
&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>rudionrails</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3443</id>
    <published>2007-08-24T09:32:17Z</published>
    <updated>2007-08-24T09:32:17Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by rudionrails</title>
<content type="html">&lt;p&gt;Oops I just noticed that textile messed up the message a little :-S
I did not mean to make things bold. There is a &lt;em&gt;star&lt;/em&gt; between the find_by_contents quotes to get all records :-)&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>rudionrails</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3442</id>
    <published>2007-08-24T09:28:48Z</published>
    <updated>2007-08-24T09:28:48Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by rudionrails</title>
<content type="html">&lt;p&gt;Hi again,&lt;/p&gt;


	&lt;p&gt;I&#8217;ve just double checked and my ferret search returns the total_hits like I explained above.&lt;/p&gt;


	&lt;p&gt;I have 3 test records in my DB. Using find_by_contents(&#8220;&lt;strong&gt;&#8220;) returns all three as expected. Using find_by_contents(&#8220;&lt;/strong&gt;&#8221;, { :limit =&amp;gt; 1 }) returns only 1 record (kind of as expected, too). I use ferret 0.11.4, perhaps there lies a difference? Or am I doing something wrong?&lt;/p&gt;


	&lt;p&gt;Rudi&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3434</id>
    <published>2007-08-23T17:37:50Z</published>
    <updated>2007-08-23T17:37:50Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Brandon</title>
<content type="html">&lt;p&gt;rudionrails,&lt;/p&gt;


	&lt;p&gt;You talk rubbish! ;)&lt;/p&gt;


	&lt;p&gt;I know the code above works because I&#8217;m using it in production.  &lt;code&gt;total_hits&lt;/code&gt; on the result object returned by &lt;code&gt;find_by_contents&lt;/code&gt; isn&#8217;t the number of results returned, but the number of hits in the ferret index.  So even if you limit the results returned (which acts_as_ferret limits to 10 by default), the &lt;code&gt;total_hits&lt;/code&gt; will still give you the total count.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>rudionrails</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3433</id>
    <published>2007-08-23T15:49:54Z</published>
    <updated>2007-08-23T15:49:54Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by rudionrails</title>
<content type="html">&lt;p&gt;Hi there,&lt;/p&gt;


	&lt;p&gt;I am not 100% sure now, but I think there&#8217;s a flaw in your code. This pagination will never appear.&lt;/p&gt;


	&lt;p&gt;You pass the offset and limit to the find_by_contents method, so the total_hits will never be above the per_page value. Hence, no pagination after all. 
You need to run the find_by_contents without offset and limit first to get the &#8220;true&#8221; total_hits for your search. Then you can paginate.&lt;/p&gt;


	&lt;p&gt;The way to go is running the ferret search two times. Once to get the total_hits and once again to get the &#8220;real&#8221; search results with offset and limit for the current page. Not very good for performance, but I haven&#8217;t found a better way yet.&lt;/p&gt;


	&lt;p&gt;Let me know if I talk rubbish ;-)
Cheers, Rudi&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Adam Roth</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:3392:3393</id>
    <published>2007-08-17T06:08:04Z</published>
    <updated>2007-08-17T06:08:04Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>Comment on 'acts_as_ferret will_paginate' by Adam Roth</title>
<content type="html">&lt;p&gt;Very niiiice.&lt;/p&gt;</content>  </entry>
</feed>
