2009-06-28 58 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()