Djapian supports a dot notation to resolve fields and the path parts of tags in Indexer declarations. It also supports callables and using their result.
However, you don't need any of that since you just need to get all comments for a restaurant, you may simply do:
class RestaurantIndexer(Indexer):
tags = [
('name','name'),
('city','city'),
('country','country.name'),
('category', 'category'),
('tag','tag'),
('comments', 'all_comments_text'),
]
class Restaurant(models.Model):
# ... fields
@property # could also be a method, since callables work
def all_comments_text(self):
return " ".join(map(lambda x: x.comment, self.comment_set.all()))
Note that this simply joins all comment fields on all related comment objects with a space. Should do for indexing, though.
stefanw
2010-01-26 12:18:13