我使用的是默認的後臺數據庫實現搜索功能在我的項目工作鶺鴒默認搜索不與未英語領域
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