Forum: Ferret Search scoping in acts_as_ferret

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
6b71251b5261e1fe3142bf620e573724?d=identicon&s=25 Giuseppe Bertini (giuseb)
on 2007-05-24 17:33
I am exploring acts_as_ferret, and the first question that pops to mind
is scoping, i.e. how to restrict searches in various ways.

For example, I have a Post model with title, content, and user_id as
attributes, and I want users to be able to search through their own
posts only.

Normally, of course, I would do
Post.find(:all, :conditions=>["user_id=?", current_user],

What about ferret-ized models?
Is there a clean way to impose such restrictions to the ferret search
itself, or should one search the entire model first, and then use the
returned ids to run a regular query with a "in" clause?

Apologies if the answer to this is trivial, I cannot seem to google the
relevant info.

0b437712d774b52475c8d265d72ae4b1?d=identicon&s=25 Doug Smith (Guest)
on 2007-05-24 17:57
(Received via mailing list)
Just add something like this to your query string:


I typically use a drop-down on the view to let the user choose limiting
values like this, then I concatenate the field values in the query
before calling find_by_contents or whatever.

You can find out a lot more about other query related options in the
documentation too:


This topic is locked and can not be replied to.