elasticsearch 自定义搜索字段中的wagtail搜索不起作用
我正在用wagtail实现一个简单的博客。对于博客页面,搜索还应该查看两个自定义字段“简介”和“正文”。我的博客页面模型如下:elasticsearch 自定义搜索字段中的wagtail搜索不起作用,elasticsearch,django-models,wagtail,elasticsearch,Django Models,Wagtail,我正在用wagtail实现一个简单的博客。对于博客页面,搜索还应该查看两个自定义字段“简介”和“正文”。我的博客页面模型如下: class PageWithSidebar(Page): def get_context(self, request): context = super(PageWithSidebar, self).get_context(request) context['tags'] = BlogPageTag.objects.all().
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"),
]
对于“title”字段,搜索工作正常,但对于两个自定义字段,搜索工作不正常。如果我搜索只包含在“简介”或“正文”字段中的单词,则不会得到任何结果
知道我缺少什么吗?我不知道默认搜索后端不支持自定义字段。切换到elasticsearch后,将包括自定义字段。您使用的是哪个搜索后端?默认后端是有限的,不支持自定义字段。我使用的是默认的。在实际设置elasticsearch后,一切都按预期进行。ThxFYI:我刚刚发现Wagtail v1.10还支持Postgres的全文搜索,这将不再需要ElasticsearchNice信息!谢谢