Flarum Supports Chinese Keyword Searches Using the Database Search Engine

21,565 19

Flarum itself is not very friendly to Chinese. As versions have evolved, it has gradually begun to optimize support for Chinese, such as allowing Chinese usernames to be registered, which is indeed quite useful. However, the latest beta11 version still does not support searching Chinese content. Fortunately, MySQL has supported full-text indexes for Chinese and Japanese since version 5.7.

In addition, Flarum developers have also said that future versions will use the ElasticSearch distributed full-text search engine, because ElasticSearch is better than this method. However, it has still not been adopted to date. Please note that this method will affect database performance to a certain extent.

Method

Modify mysql.cnf and add:

INI
[mysqld]
ngram_token_size=2

After making the modification, you need to rebuild the FULLTEXT indexes:

SQL
ALTER TABLE flarum_posts DROP INDEX content;
CREATE FULLTEXT INDEX content ON `flarum_posts` (`content`) WITH PARSER ngram;

ALTER TABLE flarum_discussions DROP INDEX title;
CREATE FULLTEXT INDEX title ON `flarum_discussions` (`title`) WITH PARSER ngram;

After rebuilding them, clear the cache in the Flarum admin panel. You will then be able to search Chinese content, including article titles and article content.

Search Chinese content

Comments

(19)
  1. Chrome 79 Windows 10

    mysql.cnf在哪里呀?

    1. Chrome 79 Windows 10

      错误 SQL 查询: ALTER TABLE flarum_posts DROP INDEX content MySQL 返回: 文档 #1146 - Table 'fl.flarum_posts' doesn't exist

  2. QAQ
    Chrome 78 Windows 10

    怎么才能中文注册

    1. Chrome 78 Windows 10

      注册时候显示“用户名只能包含字母、数字及横线 (-)” 不能注册 请问怎么设置?

  3. 木头人
    Chrome 96 Windows 7

    只想夸你,解决了我的问题

  4. Edge 101 Windows 10

    感谢,问题解决了~

  5. 78789797
    Edge 103 Windows 10

    成功了 点赞 好评

Leave a comment