Jens K. wrote:
Good point, I’ll think about how this could be done.
Ideally one would only need to specify the relationship itself as a
field, and let aaf rely on the related objects to implement some method
returning the textual content for indexing:
class Article
has_many :comments
acts_as_ferret :fields => [ :title , :body, :comments ]
end
class Comment
belongs_to :article
def to_ferret
“#{title} #{body}”
end
end
Finding out the Comment class from looking at the relationship should be
possible as AR does exactly the same.
What do you think?
Well, I think this would be fine for most of the cases, maybe you could
give a default implementation of “to_ferret” method which return a
string contains all the columns except “id” but I’m not sure if this is
a good idea anyway.
Another thing is how to deal with the multi-layer associations. Say
“Comment” has many “SomethingElse”. Now I want to treat an article, all
its comments and all the comments’ something_elses as a single item in
ferret. Then I’d have to define the “to_ferret” method in a more
complicated way(loop all the associations and get their contents).
The problem here is that any ActiveRecord model which has
“acts_as_ferret” declaration will be indexed as an individual item by
ferret. If I can use something like “acts_as_ferret_child” to tell
ferret that I want to index a model as part of another model rather than
an individual one, then the whole structure should be clear and simple.
For example:
Class Article << ActiveRecord::Base
This tells ferret to index article model as a single item.
acts_as_ferret
has_many :comments
end
Class comment << ActiveRecord::Base
This tells ferret to index comments as part of its parent article.
acts_as_ferret_child :parent => :article
belongs_to :article
end
I’m not sure whether this is feasible but I think it’s possible. And I
think there should be a way to automatically find the relationships
between models after they’ve declared by “has_many” .etc. If I’m right,
then we can get ride of the “:parent” parameter.