gitzaai/cnsearch is a Flarum 2 extension that uses Meilisearch as the discussion search backend. It indexes discussion titles and visible comment content, then plugs into Flarum's built-in discussion search flow.
- Uses Meilisearch for discussion full-text search.
- Stores one Meilisearch document per discussion.
- Merges visible comment posts into each discussion document.
- Adds CJK n-gram fields for Chinese, Japanese, Korean, and other CJK search terms.
- Lowers the forum search trigger length so 1-2 character Chinese queries can run.
- Provides admin APIs and console commands for status checks, connection tests, search tests, and reindexing.
- Syncs the index when posts or discussions are created, edited, hidden, restored, or deleted.
composer require gitzaai/cnsearch
php flarum assets:publish
php flarum cache:clearFor Flarum 2.0 beta 8 and newer, run php flarum assets:publish after installing or updating the extension to make sure frontend assets match the current extension code.
The extension does not ship with a preset Meilisearch host or API key. Configure them in the admin panel, or use the bundled command:
php flarum cnsearch:configure https://your-meilisearch.example --index=flarum_discussions
php flarum cache:clearIf your Meilisearch instance requires authentication, provide your own key:
php flarum cnsearch:configure https://your-meilisearch.example --key=replace_with_your_key --index=flarum_discussions
php flarum cache:clearYou can also write the settings directly:
INSERT INTO settings (`key`, `value`) VALUES
('cnsearch.meili.host', 'https://your-meilisearch.example'),
('cnsearch.meili.index', 'flarum_discussions')
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`);If your Flarum database tables use a prefix, replace settings with the prefixed table name.
Rebuild the index:
php flarum cnsearch:reindexIf Flarum reports There are no commands defined in the "cnsearch" namespace., enable CN Search in the admin panel first, then run the command again.
Check status:
php flarum cnsearch:statusDocuments is the number of indexed Meilisearch documents, which normally matches the number of visible discussions. Source posts is the number of visible comment posts included in the index, and can be larger than Documents.
Test a search term directly:
php flarum cnsearch:search 中文关键词After updating the extension, these commands are useful:
composer dump-autoload -o
php flarum cache:clear
php flarum cnsearch:reindexSearch:
curl "https://your-flarum-site.example/api/cnsearch/search?q=keyword&page=1&perPage=20"Status checks and reindexing require an admin session:
curl "https://your-flarum-site.example/api/cnsearch/status"
curl -X POST "https://your-flarum-site.example/api/cnsearch/reindex"
curl "https://your-flarum-site.example/api/cnsearch/test-connection"
