Sidney Burks
2006-Sep-18 04:32 UTC
[Ferret-talk] Automatic reindexing of associated columns acts_as_taggable
Hi, 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..? Thanks, -Sidney -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2006-Sep-18 11:39 UTC
[Ferret-talk] Automatic reindexing of associated columns acts_as_taggable
Hi! On Mon, Sep 18, 2006 at 06:32:27AM +0200, Sidney Burks wrote:> Hi, > > 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)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 kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
Eric Pugh
2006-Sep-18 12:31 UTC
[Ferret-talk] Automatic reindexing of associated columns acts_as_taggable
I was noticing a similar problem as well.. This looks like the solution for me! thanks... Eric On Sep 18, 2006, at 12:39 PM, Jens Kraemer wrote:> Hi! > > On Mon, Sep 18, 2006 at 06:32:27AM +0200, Sidney Burks wrote: >> Hi, >> >> 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) > > 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 kraemer at webit.de > Schnorrstra?e 76 Tel +49 351 46766 0 > D-01069 Dresden Fax +49 351 46766 66 > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk