我使用的是默认的后台数据库实现搜索功能在我的项目工作鹡鸰默认搜索不与未英语领域
class BlogPage(Page):
date = models.DateField("Post date")
intro = models.CharField(max_length=250)
body = StreamField([
('heading', blocks.CharBlock(classname="full title")),
('paragraph', blocks.RichTextBlock()),
('image', ImageChooserBlock()),
('code', CodeBlock()),
])
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
search_fields = Page.search_fields + [
index.SearchField('intro'),
index.SearchField('body'),
]
...
和搜索工作以及只有body
BlogPage
模型中的字段是英文的,如果我尝试在body
字段中使用一些俄语单词,那么它不搜索任何东西。 我看着数据库和我看到BlogPage
具有body
场这样的:
[{"value": "\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439", "id": "3343151a-edbc-4165-89f2-ce766922d68e", "type": "heading"}, {"value": "<p>\u0442\u0435\u0441\u0442\u0438\u043f\u0440</p>", "id": "22d3818d-8c69-4d72-967e-7c1f807e80b2", "type": "paragraph"}]
那么,问题是鹡鸰节省Streamfield领域的Unicode字符,如果我手动在phpMyAdmin改成这样:
[{"value": "Тест", "id": "3343151a-edbc-4165-89f2-ce766922d68e", "type": "heading"}, {"value": "<p>Тестовый</p>", "id": "22d3818d-8c69-4d72-967e-7c1f807e80b2", "type": "paragraph"}]
然后搜索开始工作,所以也许有人知道如何防止w from在unicode中保存Streamfield
字段?
你没有提到你正在使用哪个搜索后端。你使用Elasticsearch吗?我成功地使用Elasticsearch合并德语搜索。看起来你没有[为索引添加额外的字段](http://docs.wagtail.io/en/v1.12.2/topics/search/indexing.html#indexing-extra-fields)。或者你是否忽略了''BlogPage''的search_fields声明? – Moritz
我已经指定了search_fields(将这些行添加到问题中),并且我猜即时在使用默认数据库后端进行搜索。我应该怎么做才能切换到Elasticsearch?我应该将数据库更改为elastichsearch并更改wagtailsearch配置? – Alexey
你应该看看[docs](http://docs.wagtail.io/en/v1.12.2/topics/search/backends.html#elasticsearch-backend)开始。不过,PostgreSQL后端更容易[设置](http://docs.wagtail.io/en/v1.12.2/reference/contrib/postgres_search.html#postgres-search)。 – Moritz