Ian Zabel
2006-Aug-06 17:07 UTC
[Ferret-talk] 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? -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2006-Aug-10 09:17 UTC
[Ferret-talk] Return only results that user is allowed to see?
On Sun, Aug 06, 2006 at 07:07:39PM +0200, Ian Zabel wrote:> 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?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 kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
Ian Zabel
2006-Aug-11 04:14 UTC
[Ferret-talk] Return only results that user is allowed to see?
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. -- Posted via http://www.ruby-forum.com/.
David Balmain
2006-Aug-11 05:05 UTC
[Ferret-talk] Return only results that user is allowed to see?
On 8/11/06, Ian Zabel <contact at ezabel.com> wrote:> 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.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
Ian Zabel
2006-Aug-15 15:22 UTC
[Ferret-talk] Return only results that user is allowed to see?
David Balmain 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 Kraemer 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 :) Thanks, Ian. -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2006-Aug-15 16:10 UTC
[Ferret-talk] Return only results that user is allowed to see?
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 Zabel wrote:> David Balmain 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 Kraemer 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 :) > > Thanks, > Ian. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk-- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66