2017-05-19 14 views
1

私はwagtailで簡単なブログを実装しています。ブログページの場合、検索では2つのカスタムフィールド 'イントロ'と 'ボディ'も検索する必要があります。次のように私のBlogPage-モデルは次のとおりです。カスタム検索フィールドでのwagtail検索が機能しない

class PageWithSidebar(Page): 

    def get_context(self, request): 
     context = super(PageWithSidebar, self).get_context(request) 
     context['tags'] = BlogPageTag.objects.all().select_related().values('tag_id', 'tag_id__name').annotate(item_count=Count('tag_id')).order_by('-item_count')[:10] 
     context['categories'] = BlogCategory.objects.values('name').annotate(Count('name')).values('name').order_by('name') 
     context['recent_blogpages'] = Page.objects.filter(content_type__model='blogpage').filter(live='1').order_by('-first_published_at') 

     return context 

class BlogPage(PageWithSidebar): 


date = models.DateField("Post date") 
     intro = models.CharField(max_length=250) 
     body = RichTextField(blank=True) 
     tags = ClusterTaggableManager(through=BlogPageTag, blank=True) 
     categories = ParentalManyToManyField('blog.BlogCategory', blank=True) 
     social_description = models.CharField(max_length=140, blank=True) 

     def main_image(self): 
      gallery_item = self.gallery_images.first() 
      if gallery_item: 
       return gallery_item.image 
      else: 
       return None 

     def main_image_caption(self): 
      gallery_item = self.gallery_images.first() 
      if gallery_item: 
       return gallery_item.caption 
      else: 
       return None 

     search_fields = PageWithSidebar.search_fields + [ 
      index.SearchField('intro'), 
      index.SearchField('body'), 
     ] 

     content_panels = PageWithSidebar.content_panels + [ 
      MultiFieldPanel([ 
       FieldPanel('date'), 
       FieldPanel('tags'), 
       FieldPanel('categories', widget=forms.CheckboxSelectMultiple), 
       FieldPanel('social_description'), 
      ], heading="Blog information"), 
      FieldPanel('intro'), 
      FieldPanel('body'), 
      InlinePanel('gallery_images', label="Gallery images"), 
     ] 

検索は「タイトル」フィールドのためではなく、2つのカスタムフィールドに対してだけで正常に動作します。私はちょうど 'イントロ'または 'ボディ'フィールドに含まれている単語を検索すると、結果は得られません。

アイデアは何ですか?

+0

どのバックエンド検索を使用していますか?デフォルトのバックエンドは限定されており、カスタムフィールドをサポートしていません – dentemm

+0

私はデフォルトのバックエンドを使用していました。実際にelasticsearchを設定した後は、すべてが期待通りに機能します。 Thx – Mischa

答えて

0

デフォルトの検索バックエンドがカスタムフィールドをサポートしていないことはわかりませんでした。 elasticsearchに切り替えた後、カスタムフィールドが追加されました。

+0

参考:Wagtail v1.10もPostgresのフルテキスト検索をサポートしていることがわかりました。これはElasticsearchの必要性を低下させます。 – dentemm

+0

素敵な情報!ありがとう – Mischa

関連する問題