# Search scoping in acts\_as\_ferret

**URL:** <https://www.ruby-forum.com/t/search-scoping-in-acts-as-ferret/104992>\
**Category:** Ferret\
**Created:** [May 24, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/search-scoping-in-acts-as-ferret/104992 "2007-05-24T17:33:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![giuseb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@giuseb](https://www.ruby-forum.com/u/giuseb)\
**Post date:** [May 24, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/search-scoping-in-acts-as-ferret/104992/1 "2007-05-24T17:33:48Z")

</div>

Hello,  
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],  
:joins=\>“somejoins”)

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.

Cheers,  
Giuseppe

---

<div class="post-metadata">

**Author:** ![giuseb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@giuseb](https://www.ruby-forum.com/u/giuseb)\
**Post date:** [May 24, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/search-scoping-in-acts-as-ferret/104992/2 "2007-05-24T17:57:35Z")

</div>

Just add something like this to your query string:

“user\_id:10”

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  
string  
before calling find\_by\_contents or whatever.

You can find out a lot more about other query related options in the  
Lucene  
documentation too:  
[http://lucene.apache.org/java/docs/queryparsersyntax.html](http://lucene.apache.org/java/docs/queryparsersyntax.html)

Thanks,

Doug
