2009-06-28 12 views
0

私はdjapoベースの全文検索を実装して、ユーザー のプロファイルを私のdjangoサイトで検索しようとしています。 djapianインデクサーを追加したモデルのプロフィールを更新しましたdjapianベースの検索結果は返されません

  • :私は基本的に 索引を作成するには、次の手順に従いました。
  • Ran python manage.py index --rebuildインデックスを再構築する。しかし

私が使用してプロファイルのインデクサを使用して検索してみてください:
Profile.indexer.search("query")
それは私に何も結果を与えるものではありません。私は何の誤りもありません。

誰か助けてもらえますか?私は初心者です。 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

してください、私たちにあなたのインデクサーの定義を与え、どこで教えてそれはコードで生きていますか? –

+0

レスポンスAlexに感謝します。あなたの質問に答えるために投稿を更新しました。 – kartikq

答えて

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() 
+1

レモード、それはうまくいった。私はインデックス--rebuildがインデックスを再構築すべきだと考えました。どうもありがとうございました! – kartikq

関連する問題