flarum 论坛中文搜索插件

Overview

Flarum 论坛中文搜索typesense引擎案例

License Latest Stable Version Total Downloads

案例参考了flarum-elasticsearchflarum-ext-chinese-search

version

PHP 7.4.7

Flarum 1.0.4

Typesense 0.21.0

MySQL 8.0.25

Mysql ngram中文搜索

比起第三方搜索引擎,Mysql内置应该是最简单

如果你不想用typesense搜索引擎 使用mysql的ngram也可以实现中文搜索

1、在my.cnf中设置ngram_token_size属性

例如,"Happy Birthday"是 "生日快乐"简体中国,在 "生日"是 "birthday"和 "快乐"翻译为"happy"。要搜索诸如此类的两个字符的词,请将ngram_token_size 值设置为 2 或更高。

[mysqld]
ngram_token_size=2

重建索引

1、把discussions表中的索引字段title删除,执行下列语句重新建立索引

ALTER TABLE 你的表头_discussions ADD FULLTEXT INDEX title (title) WITH PARSER ngram;

2、把posts表中的索引字段content删除,执行下列语句重新建立索引

ALTER TABLE 你的表头_posts ADD FULLTEXT INDEX content (content) WITH PARSER ngram;

就这样你就可以使用中文搜索了。

安装插件

composer require mkm/flarum-typesense-chinese-search *@dev

Typesense sdk

composer require php-http/curl-client typesense/typesense-php

说明

1、PHP 版本必须大于7.4,否则typesense引擎的sdk包会是2.0的不是4.7.0

2、typesense引擎必须是最新版的0.21.0,否则没有中文索引

3、在根目录下的extend.php里添加以下代码

        (new Extend\Routes('api'))
        ->remove('discussions.index')

4、在根目录下的config.php里添加以下代码

'typesense' => 
  array (
    'key' => "Hu52dwsas2AdxdE",//typesense密钥
    'host' => '127.0.0.1',
    'port' => 8108,
    'protocol' => 'http',
    'indexTableDiscussions'=>"discussions",//数据库discussions表的表名 不带前缀
    'indexTablePosts'=>"posts",数据库posts表的表名 不带前缀
    'connection_timeout_seconds' => 2,//连接超时秒
  ),

6、到这里你就可以在你本地论坛测试中文搜索了,没怎么使用laravel有些地方有些冗余。所以希望大家自己能改改 也可以提交issues。

You might also like...
Owner
mkm
mkm
Flarum Post Comments - A Flarum extension.

Flarum Post Comments A Flarum extension. Make sure to comment on the answers and list the comments below the answers. Installation Install with compos

Selçuk Kılıç 2 Sep 22, 2022
Encryption-free Private Messaging For Flarum

Whisper - Private Messaging for Flarum A Flarum extension. Add private messaging functionality to your Flarum Community! Simple to install, no setting

Charlie 4 Dec 7, 2021
Support search in flarum by sonic

flarum-sonic Support search by Sonic Install Sonic following this guide Install the extension: composer require ganuonglachanh/sonic Change info in a

null 18 Dec 21, 2022
Generate pseudo-static pages from markdown and HTML files for Flarum

Flarum Pages Generator This is not a Flarum extension. This package provides a Flarum extender that you can use in the local extend.php to define cust

Clark Winkelmann 7 Feb 21, 2022
Sign into your Flarum forum with your Amazon account

Log In With Amazon A Flarum extension. Log in to your Flarum forum with Amazon. An addon for FoF OAuth Installation Install with composer: composer re

Ian Morland 0 May 4, 2022
A Flarum extension. A MEME BBCode.

Meme A Flarum extension. A MEME BBCode. [meme url=image.jpg text-position=top, center, bottom]This is meme text.[/meme] Installation Install with comp

Billy Wilcosky 2 Nov 26, 2021
ECNU Forum based on Flarum.

ECNU Forum ECNU Forum based on Flarum. Welcome to ECNU Forum, where every ECNU student can speak freely. Note that this is not an official forum of EC

null 54 Dec 13, 2022