Patrick Aljord
2007-May-25 02:27 UTC
[Ferret-talk] how to update index with acts_as_ferret?
Hey all,
I have movie has_many :medias and media belongs_to :media
this is how my movie class looks like:
class Movie < ActiveRecord::Base
has_many :medias
acts_as_ferret :fields => [:title,:medias_name]
def medias_name
return self.medias.inject("") {|name,m| name + " " +
m.name}
end
end
when I do Movie.find_by_contents("title:bob") it does return a movie
and if I modify that movie title to Bill and do
Movie.find_by_contents("title:bill") it will return the movie also.
But if I create a new media xyz and try to search on it
Movie.find_by_contents("medias_name:xyz") it doesn''t find
it, I need
to rm -rf index/ and restart the server to make it find it. Any idea
how I can update the index on special fields?
thanx in advance
Pat
Hi! On Fri, May 25, 2007 at 04:27:35AM +0200, Patrick Aljord wrote:> Hey all, > I have movie has_many :medias and media belongs_to :media > > this is how my movie class looks like: > > class Movie < ActiveRecord::Base > has_many :medias > > acts_as_ferret :fields => [:title,:medias_name] > > def medias_name > return self.medias.inject("") {|name,m| name + " " + m.name} > end > > end > > when I do Movie.find_by_contents("title:bob") it does return a movie > and if I modify that movie title to Bill and do > Movie.find_by_contents("title:bill") it will return the movie also. > > But if I create a new media xyz and try to search on it > Movie.find_by_contents("medias_name:xyz") it doesn''t find it, I need > to rm -rf index/ and restart the server to make it find it. Any idea > how I can update the index on special fields?you can''t update single fields, you havbe to reindex that movie to reflect the changes. An after_save hook in media calling movie.ferret_update should do the trick. 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