My model's full_text_search method looks like:

    def self.full_text_search(q, options = {})
      return nil if q.nil? or q.empty?
      default_options = {:limit => 10, :page => 1}
      default_options.update options

      # get the offset based on the page and limit
      default_options[:page] = 1 if default_options[:page] == 0
      default_options[:offset] = default_options[:limit] * 
(default_options.delete(:page).to_i-1)

      # now do the query with options
      results = Article.find_by_contents(q, default_options)
      return [results.total_hits, results]
    end

My search controller uses it like this:

# build sort
@sf_published_at = Ferret::Search::SortField.new(:published_at_string, 
:type => :string, :reverse => true)
@sort = Ferret::Search::Sort.new(@sf_published_at)

# set options
@options = {:limit => 20, :sort => @sort}

@total, @articles = Article.full_text_search(@query_string, @options)

And yes, you're absolutely right about sending in :limit => :all.  I 
forgot to mention that in my earlier post.

I'm currently getting around this issue by returning all the results and 
sorting in ruby.

Thanks for looking into this.

Sanjay

Jens Kraemer wrote:
> Hi!
> 
> On Tue, Mar 06, 2007 at 06:39:13AM +0100, Sanjay Kapoor wrote:
>> I did some further testing using the DRb setup.  This time, I kept the 
>> sort but removed the :limit and :offset options.  The results were not 
>> properly sorted and only 10 items were returned, even though there are 
>> 48 matching results and no limit imposed on the query.  Then I removed 
>> the DRb from the setup and the 48 results came back properly sorted in a 
>> single query.
> 
> Looks like you just found a bug in the DRb code - I'll try to fix this
> asap. Could you please post your call to find_by_contents, including the
> construction of your SortFields?
> The acts_as_ferret statement in your model might help, too.
> 
> About the number of results returned - are you sure you got all 48
> results back from a call to find_by_contents without :limit parameter?
> By default only 10 hits will be returned and you'll need to pass
> :limit => :all for aaf to give you all results. However
> results.total_hits will give you the total number of results. Maybe only
> that value is different with or without DRb?
> 
> Jens
> 
> 
> --
> 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
> [EMAIL PROTECTED] | www.webit.de
> 
> Amtsgericht Dresden | HRB 15422
> GF Sven Haubold, Hagen Malessa


-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to