wagtail에서 간단한 블로그를 구현하고 있습니다. 블로그 페이지의 경우 검색은 두 개의 사용자 정의 필드 인 '소개'와 '본문'을 조사해야합니다. 다음과 같이 내 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"),
]
검색이 아니라 두 개의 사용자 정의 필드의 '제목'필드에 대해 잘 작동합니다. '소개'또는 '본문'입력란에 방금 들어있는 단어를 검색하면 결과가 표시되지 않습니다.
내가 누락 된 아이디어가 있습니까?
어떤 백엔드를 사용하고 있습니까? 기본 백엔드는 제한되어 있으며 사용자 정의 필드를 지원하지 않습니다. – dentemm
기본 백엔드를 사용하고있었습니다. 실제로 elasticsearch를 설정하면 모든 것이 예상대로 작동합니다. Thx – Mischa