# Is this the best approach?

**URL:** <https://www.ruby-forum.com/t/is-this-the-best-approach/83678>\
**Category:** Ferret\
**Created:** [January 28, 2007, 7:08pm UTC](https://www.ruby-forum.com/t/is-this-the-best-approach/83678 "2007-01-28T19:08:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doug\_Pfeffer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@Doug\_Pfeffer](https://www.ruby-forum.com/u/Doug_Pfeffer)\
**Post date:** [January 28, 2007, 7:08pm UTC](https://www.ruby-forum.com/t/is-this-the-best-approach/83678/1 "2007-01-28T19:08:03Z")

</div>

Hello,  
I’m working on a Rails app with a fairly complex set of model  
relationships. I’m abandoning my MySQL based search mechanism for  
Ferret/acts\_as\_ferret in the hopes of being able to more easily and  
effectivly enable searching. Before I get coding I was wondering if you  
folks might be able to tell me if my plan makes sense, or what could be  
a better way. The situation is as follows:

Users of the app all “own” a variety of data. Most of the time only the  
creator of an object has access to it, but there are also scenarios when  
multiple users have access to a single object. No object can be  
manipulated without knowledge of what user is making the request. This  
makes searching difficult because I’ve got to filter the results based  
not just on the search params but by user permissions as well.

At this point I plan on using a single index, with :store\_class\_name  
enabled for all models. The tricky part is limiting the search results  
to only the items the searching user has access to. I think the easiest  
way to do with would just to store an “owner\_id” along with every entry  
in the index, which would be the User’s ID in my database. So for every  
search I’d include the user’s id as a requirement. The downside is that  
I’ll need to have redundant data for multi-owner situations, with one  
entry for each user that has access to it. This will make managing  
deletes and edits complicated (and slow?) because the system will need  
to be removing/creating multiple instances of the same entry in the  
index.

The end result of this approach is a sort of flattened clone of the  
database, which seems a little awkward, but I’m not sure how else to go  
about it. I could just do a regular search by content and filter the  
results after the fact, but that seems kind of crappy too.

Hopefully that made sense. Is there a better way to do this? Did I leave  
out any details?

Thanks!  
Doug

---

<div class="post-metadata">

**Author:** ![Doug\_Pfeffer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@Doug\_Pfeffer](https://www.ruby-forum.com/u/Doug_Pfeffer)\
**Post date:** [January 28, 2007, 9:40pm UTC](https://www.ruby-forum.com/t/is-this-the-best-approach/83678/2 "2007-01-28T21:40:41Z")

</div>

On 28.01.2007, at 19:08, Doug Pfeffer wrote:

> I’ve got to filter the results based  
> not just on the search params but by user permissions as well.

You can store multiple user ids in a single field (:owners) and limit  
the search to only those documents that contain the currents user’s  
id in that field.

Cheers,  
Andy
