2009-06-28 18 views
0

我正在尝试在我的django网站中搜索用户 配置文件的基于djapian的全文搜索。我基本上按照以下步骤来构建 索引:基于djapian的搜索不返回结果

  • 更新了模型配置文件以添加djapian索引器。
  • python manage.py index --rebuild重建索引。

然而,当我尝试使用使用档案索引搜索:
Profile.indexer.search("query")
它并没有给我任何结果。我没有收到任何错误。

有人可以帮助我吗?我是新手w.r.t. Django的+ djapian。

---更新06/29/09
我的索引定义住在models.py和如下:


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') 

+0

请给我们您的索引定义和分不清哪里它住在代码中吗? – 2009-06-29 06:59:37

+0

感谢Alex的回应。我更新了我的帖子来回答你的问题。 – kartikq 2009-06-30 04:23:04

回答

1

这可能是因为你缺少运行

Profile.indexer.update() 

在models.py的结尾(你只需要做一次)。

现在,我可能会使用比你的旧版本Djapian,但以下似乎为我(models.py结束)工作:

profile_indexer = djapian.Indexer(
    model=Profile, 
    fields=[..., ...], 
    tags=[(..., ...), (..., ...)] 
) 
# Run once and then comment out. 
Profile.indexer.update()