Defining an index combining two tables

4 views
Skip to first unread message

jul

unread,
Jan 4, 2010, 3:09:30 PM1/4/10
to Djapian Users
hi,

I've got the following Restaurant and the Comment models. I'm doing
full text search on some fields of the Restaurant model, as shown
below in the RestaurantIndexer class. How can I do a full text search
including the comments (i.e. a search returning Restaurant instances
with the query contained in one or some fields defined in
RestaurantIndexer or in the comment field of Comment instances)?

*********Restaurant model***************

class Restaurant(models.Model):

name = models.CharField(max_length=100)
country=models.ForeignKey(Country)
city=models.ForeignKey(City)
street=models.CharField(max_length=100)
street_number=models.PositiveSmallIntegerField()
postal_code=models.PositiveIntegerField(blank=True,
null=True)
category=models.ManyToManyField(Category, blank=True,
null=True)
slug = models.SlugField(unique=True)


*********Comment model***************

class Comment(models.Model):

user = models.ForeignKey(User)
restaurant = models.ForeignKey(Restaurant)
submit_date = models.DateTimeField(blank = True, null = False)
comment = models.TextField()


*********Restaurant indexer***************

class RestaurantIndexer(Indexer):
tags = [
('name','name'),
('city','city'),
('country','country'),
('category', 'category'),
('tag','tag')
]

space.add_index(Restaurant, RestaurantIndexer, attach_as='indexer')

Alex Koshelev

unread,
Jan 17, 2010, 8:55:56 PM1/17/10
to djapia...@googlegroups.com
Hi again, jul!

My advise is to add some method to the Restaurant model that will return all its comments text. Than index value returned by this method and search against it.

---
Alex Koshelev



--

You received this message because you are subscribed to the Google Groups "Djapian Users" group.
To post to this group, send email to djapia...@googlegroups.com.
To unsubscribe from this group, send email to djapian-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/djapian-users?hl=en.



jul

unread,
Jan 25, 2010, 5:02:05 PM1/25/10
to Djapian Users
Can you explain please? I can add a function to the restaurant model
to get all the comments, but how can I add the result to the index?
thanks for your reply.

> > djapian-user...@googlegroups.com<djapian-users%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages