Max, seems to me that your code would help to make things more robust, 
if it's a public API then it should stand up to a little abuse in ways 
not intended. maybe more of an enhancement than a bug fix, but a fix 
just the same.



Max Williams wrote:
> I'm using acts_as_ferret, passing through multiple classes using :multi
> and also some conditions.  The way i'm doing this, which seems a bit
> dirty (but it's the only way i can work out) is to call find_by_contents
> on the first element in an array of classes (called 'classes' here), and
> then point :multi at the rest of the array of classes:
> 
> @search_results = classes.first.find_by_contents(@search.term,
>             #(ferret) options
>             {:page => (params[:page] || 1),
>             :per_page => 10,
>             :multi => classes.slice(1, classes.length) },
>             #find_options
>             {:conditions => ["id = ?", 99]}
>           )
> 
> However, if classes has only one class in it, then :multi points to an
> empty array, which seems to confuse the find_by_contents method - for
> example, when doing a search on a single class, with a condition that
> should return 1 result, 'total_hits' equals 1 but @search_results is
> empty.
> 
> Following the code through method calls in the class_methods file in
> acts_as_ferret, it seems that having a value for :multi but not having
> any classes in it causes some confusion.
> 
> To get around this, i added the following line at the start of the
> find_with_ferret method (which is an alias for find_by_contents) -
> 
>   options.delete :multi if options[:multi] == []
> 
> This removes the confusion and everything's fine as far as i can tell.
> My question is this - should what i've done be considered a bug fix for
> find_with_ferret, or is the fault mine for sometimes pointing :multi at
> an empty array in my call?

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

Reply via email to