I am trying to implement a djapian based full text search for searching user
profiles in my django site. I basically followed the following steps to build the
indexes:
- Updated the model Profile to add the djapian indexer.
- Ran
python manage.py index --rebuildto rebuild the indexes.
However when I try to search using the Profile indexer using:
Profile.indexer.search("query")
it does not give me any results. I do not receive any errors.
Can someone help me with this? I am a newbie w.r.t. django+djapian.
—Update 06/29/09
My indexer definition lives in models.py and is as follows:
class Profile(models.Model):
user = models.ForeignKey(User, unique=True, verbose_name=('user'))
name = models.CharField(('name'), max_length=50, null=True, blank=True)
about = models.TextField(('about'), null=True, blank=True)
institution = models.CharField(('institution'),max_length=100,null=True, blank=True)
location = models.CharField(_('location'), max_length=40, null=True, blank=True)
website = models.URLField(_('website'), null=True, blank=True, verify_exists=False)
def unicode(self):
return self.user.username
def get_absolute_url(self):
return ('profile_detail', None, {'username': self.user.username})
get_absolute_url = models.permalink(get_absolute_url)
class Meta:
verbose_name = _('profile')
verbose_name_plural = _('profiles')
class ProfileIndexer(djapian.Indexer):
fields = ['name', 'about', 'institution','location']
tags = [ ('name','name'),('about','about'),('institution','institution'),('location','location')]
djapian.add_index(Profile,ProfileIndexer,attach_as = 'indexer')
It’s possible that all you are missing is running
at the end of models.py (you only have to do this once).
Now, I might be using an older version of Djapian than you but the following seem to work for me (end of models.py):