Pedro Côrte-Real
2006-Aug-25 11:10 UTC
[Ferret-talk] disabling automatic indexing in acts_as_ferret
I''d like to be able to enable/disable the automatic indexing of documents acts_as_ferret does. Something like MyModel.disable_indexing MyModel.enable_indexing would be perfect. I need this because I do some indexing that requires visiting the parents of the model objects and my import method imports the children first, so the information isn''t there yet. I''d like to disable the indexing, do all the importing and then manually index the documents. Having a MyModel#index would be great for this too. Is there anything of the sort? Pedro.
Jens Kraemer
2006-Sep-01 11:26 UTC
[Ferret-talk] disabling automatic indexing in acts_as_ferret
On Fri, Aug 25, 2006 at 12:10:26PM +0100, Pedro C?rte-Real wrote:> I''d like to be able to enable/disable the automatic indexing of > documents acts_as_ferret does. Something like MyModel.disable_indexing > MyModel.enable_indexing would be perfect. I need this because I do some > indexing that requires visiting the parents of the model objects and my > import method imports the children first, so the information isn''t there > yet. I''d like to disable the indexing, do all the importing and then > manually index the documents. Having a MyModel#index would be great for > this too. > > Is there anything of the sort?there''s an instance variable @ferret_reindex that''s checked before the indexing takes place. Something like def save_noindex @ferret_reindex = false save end in your model should save the record without reindexing it. The boolean is set to true in the after_save handler again, so the next call to save should reindex again. You may call ferret_update directly to reindex without saving, too. 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
Pedro Côrte-Real
2006-Sep-07 10:33 UTC
[Ferret-talk] disabling automatic indexing in acts_as_ferret
On Fri, 2006-09-01 at 13:26 +0200, Jens Kraemer wrote:> there''s an instance variable @ferret_reindex that''s checked before the > indexing takes place. > Something like > > def save_noindex > @ferret_reindex = false > save > end > > in your model should save the record without reindexing it.This doesn''t work because of this code: def ferret_before_update @ferret_reindex = true end alias :ferret_before_create :ferret_before_update # add to index def ferret_create logger.debug "ferret_create/update: #{self.class.name} : #{self.id}" self.class.ferret_index << self.to_doc if @ferret_reindex @ferret_reindex = true true end alias :ferret_update :ferret_createe This makes @ferret_reindex always true when ferret_create runs.> The boolean > is set to true in the after_save handler again, so the next call to save > should reindex again.I''m guessing the development branch has after_ handlers instead of before_.> You may call ferret_update directly to reindex > without saving, too.This worked great. Thanks, Pedro.
Jens Kraemer
2006-Sep-07 12:07 UTC
[Ferret-talk] disabling automatic indexing in acts_as_ferret
On Thu, Sep 07, 2006 at 11:33:44AM +0100, Pedro C?rte-Real wrote:> On Fri, 2006-09-01 at 13:26 +0200, Jens Kraemer wrote: > > there''s an instance variable @ferret_reindex that''s checked before the > > indexing takes place. > > Something like > > > > def save_noindex > > @ferret_reindex = false > > save > > end > > > > in your model should save the record without reindexing it. > > This doesn''t work because of this code: > > def ferret_before_update > @ferret_reindex = true > end > alias :ferret_before_create :ferret_before_update > > # add to index > def ferret_create > logger.debug "ferret_create/update: #{self.class.name} : #{self.id}" > self.class.ferret_index << self.to_doc if @ferret_reindex > @ferret_reindex = true > true > end > alias :ferret_update :ferret_createe > > This makes @ferret_reindex always true when ferret_create runs.right, the only way to avoid this seems to be overriding ferret_beforee_update. I''ll have a look into this. Jens> > > > The boolean > > is set to true in the after_save handler again, so the next call to save > > should reindex again. > > I''m guessing the development branch has after_ handlers instead of > before_. > > > You may call ferret_update directly to reindex > > without saving, too. > > This worked great. > > Thanks, > > Pedro. > > _______________________________________________ > 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
Alain Ravet
2007-Jun-18 10:08 UTC
[Ferret-talk] disabling automatic indexing in acts_as_ferret
> I''d like to be able to enable/disable the automatic indexing ofI miss this feature badly: I need to disable aaf at the model level, before bulk-modifying the 150K rows of a table, and rebuilding the index afterwards. I wish I could write code like : Account.disable_ferret ... modify all the accounts in bulk Account.enable_ferret Account.rebuild_index Is there a best practice/semi-official hack to achieve this goal? Alain -- Posted via http://www.ruby-forum.com/.
Andreas Korth
2007-Jun-18 12:14 UTC
[Ferret-talk] disabling automatic indexing in acts_as_ferret
On 18.06.2007, at 12:08, Alain Ravet wrote:> >> I''d like to be able to enable/disable the automatic indexing of > > I miss this feature badly: I need to disable aaf at the model level, > before bulk-modifying the 150K rows of a table, and rebuilding the > index > afterwards.You can enable/disable AAF on the object level: http://projects.jkraemer.net/acts_as_ferret/wiki/ AdvancedUsage#Disablingautomaticindexing I don''t understand why it''s done that way. Disabling indexing on the class level would make a whole lot more sense. There you go. Cheers, Andy
Jens Kraemer
2007-Jun-18 18:34 UTC
[Ferret-talk] disabling automatic indexing in acts_as_ferret
On Mon, Jun 18, 2007 at 02:14:07PM +0200, Andreas Korth wrote:> > On 18.06.2007, at 12:08, Alain Ravet wrote: > > > > >> I''d like to be able to enable/disable the automatic indexing of > > > > I miss this feature badly: I need to disable aaf at the model level, > > before bulk-modifying the 150K rows of a table, and rebuilding the > > index > > afterwards. > > You can enable/disable AAF on the object level: > > http://projects.jkraemer.net/acts_as_ferret/wiki/ > AdvancedUsage#Disablingautomaticindexing > > I don''t understand why it''s done that way. Disabling indexing on the > class level would make a whole lot more sense.just override the ferret_enabled?(bool) instance method to check for a class variable holding your class level disable-flag... Jens -- Jens Kr?mer webit! Gesellschaft f?r neue Medien mbH Schnorrstra?e 76 | 01069 Dresden Telefon +49 351 46766-0 | Telefax +49 351 46766-66 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Alain Ravet
2007-Jun-18 21:22 UTC
[Ferret-talk] disabling automatic indexing in acts_as_ferret
> just override the ferret_enabled?(bool) instance method to check for a> class variable holding your class level disable-flag... I know, but it''s ugly, and indirect, and really not the way to do it for this kind of use cases : bulk change, bulk import, .. A class method is needed : Model.disable_indexing # bulk change Model.enable_indexing(true) # true => trigger a rebuild_index Alain