Django 基于djapian的搜索不返回结果

Django 基于djapian的搜索不返回结果,django,Django,我试图实现一个基于djapian的全文搜索来搜索用户 我的django站点中的配置文件。我基本上按照以下步骤来构建 索引: 更新模型配置文件以添加djapian索引器 运行python manage.py index--rebuild来重建索引 但是,当我尝试使用配置文件索引器进行搜索时,请使用: Profile.indexer.search(“查询”) 它没有给我任何结果。我没有收到任何错误。 有人能帮我吗?我是一个新来的w.r.t.django+djapian。 ---2009年6月29

我试图实现一个基于djapian的全文搜索来搜索用户 我的django站点中的配置文件。我基本上按照以下步骤来构建 索引:

  • 更新模型配置文件以添加djapian索引器
  • 运行
    python manage.py index--rebuild
    来重建索引
但是,当我尝试使用配置文件索引器进行搜索时,请使用:
Profile.indexer.search(“查询”)

它没有给我任何结果。我没有收到任何错误。

有人能帮我吗?我是一个新来的w.r.t.django+djapian。

---2009年6月29日更新
我的索引器定义位于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')

您可能缺少的只是运行

profile_indexer = djapian.Indexer(
    model=Profile,
    fields=[..., ...],
    tags=[(..., ...), (..., ...)]
)
# Run once and then comment out.
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()