So i’m trying to use acts_as_taggable with the acts_as_ferret plugin,
where I have Post.rb model, which has a method tag_list made available
through acts_as_taggable, as returns a string of associated tag words
from the tags table (tag.rb). I’ve set up my Post.rb model in the
following way.
class Post < ActiveRecord::Base
acts_as_taggable
acts_as_ferret :fields => [“title”, “description”, :tag_list]
…
end
I’m noticing that when I submit a new post, the titles and descriptions
are automatically indexed, and are searchable with ferret… However,
the tags do not show up in the results when I do a tag search. However,
once I use script console and try to manually rebuild the Post index:
Post.rebuild_index(Post)
(is this syntax even correct? it returns a result of false)
the tags immediately start to appear in the tag search results. So is
there a way to set ferret to automatically rebuild the tag index when a
Post is saved? I imagine it probably shouldn’t rebuild the entire index
for all posts every time a post is saved, as that might slow things up
eventually, right? So what would be a good solution…?
(is this syntax even correct? it returns a result of false)
you can omit the parameter in this case, as Post is the class you call
rebuild_index upon. But doesn’t hurt either.
the tags immediately start to appear in the tag search results. So is
there a way to set ferret to automatically rebuild the tag index when a
Post is saved? I imagine it probably shouldn’t rebuild the entire index
for all posts every time a post is saved, as that might slow things up
eventually, right? So what would be a good solution…?
I don’t remember right now, how acts_as_taggable works, but it
seems the tags are set after the post is indexed. Calling
post.ferret_update after applying the tags to the post object should
reindex the object with tags included (this should work in 0.2.x
versions of aaf, too). If you are concerned about performance, and use
aaf 0.3,
you can also suppress the first indexing of the non-tagged post:
post = Post.new(…)
post.disable_ferret
post.save
set tags here …
post.ferret_update
or even more elegant:
post.disable_ferret(:index_when_finished) do
post.save
set tags here
end
which calls ferret_update after executing the block.
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