Return only results that user is allowed to see?

Is it possible with acts_as_ferret to somehow restrict the results that
are returned?

For instance, I don’t want to return results that are logically deleted
with acts_as_paranoid (deleted_at IS NOT NULL and deleted_at < now()).
Also, if a user is not an Admin, they should not be able to return
results that have a certain value in a certain column, like forum_id !=
13 (if 13 is an admin only forum).

What’s the best way to accomplish this? Do I need to include the
deleted_id and forum_id columns in my index, and then pass in the
appropriate search terms in the controller?

Right now, the model I’m search is Comment, and I have this defined:

acts_as_ferret :fields => [ ‘comment’ ]

Any tips?

Just wanted to clarify a bit. I guess what I’m basically asking is how
can I use this kind of condition:

:conditions => ‘forum_id != 13’

On this model:

class Comment < ActiveRecord::Base
acts_as_paranoid
acts_as_ferret :fields => [ ‘comment’ ]
end

Do I need to add forum_id to the list of fields? And how do I write the
query?

This doesn’t seem to work…
Comment.find_by_contents(“test”, :conditions => ‘forum_id != 13’)

Thanks,
Ian.

On Sun, Aug 06, 2006 at 07:07:39PM +0200, Ian Z. wrote:

deleted_id and forum_id columns in my index, and then pass in the
appropriate search terms in the controller?

If you don’t want to filter results after getting them from
acts_as_ferret, including the information needed to filter search
results
in the index is necessary.

You could then use custom built queries to constrain searches beyond
the query terms given by the user. Another way to achieve this are query
filters, which can enhance speed in case of repeated searches with the
same filter criteria.

Jens


webit! Gesellschaft für neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66

David B. wrote:

Try adding ‘forum_id’ to your list of fields and write the query like
this;

Comment.find_by_contents("test AND NOT forum_id:13")

Jens K. wrote:

If you don’t want to filter results after getting them from
acts_as_ferret, including the information needed to filter search
results
in the index is necessary.

Thanks guys! This is what I was looking for. It makes sense that I would
have to index the appropriate columns to be able to filter on them.

Do I have to add that column to my column list and then rebuild the
index from scratch for that model? Or is there a better way? I ask
because it took about 4 hours to finish indexing the comments table
(350k rows), and the idea of rebuilding the index each time I want to
add a new column to the index is a bit daunting :slight_smile:

Thanks,
Ian.

On 8/11/06, Ian Z. [email protected] wrote:

end

Do I need to add forum_id to the list of fields? And how do I write the
query?

This doesn’t seem to work…
Comment.find_by_contents(“test”, :conditions => ‘forum_id != 13’)

Thanks,
Ian.

Hi Ian,

Try adding ‘forum_id’ to your list of fields and write the query like
this;

Comment.find_by_contents("test AND NOT forum_id:13")

or;

Comment.find_by_contents("test -forum_id:13")

Hope that helps,
Dave

Hi Ian,

yes, you’ll have to rebuild the index if you want the existing
documents to have the new field.

Jens

On Tue, Aug 15, 2006 at 05:22:53PM +0200, Ian Z. wrote:

in the index is necessary.
Thanks,
Ian.


Posted via http://www.ruby-forum.com/.


Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk


webit! Gesellschaft für neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66