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.

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 [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66

On Fri, 2006-09-01 at 13:26 +0200, Jens K. 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.

On Thu, Sep 07, 2006 at 11:33:44AM +0100, Pedro Côrte-Real wrote:

in your model should save the record without reindexing it.
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

without saving, too.
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

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.

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

On 18.06.2007, at 12:08, Alain R. 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

On Mon, Jun 18, 2007 at 02:14:07PM +0200, Andreas K. wrote:

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
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa

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