In this section, I primarily focus on utilizing the Sonic extension to implement Chinese text search. In my case, the server-side encounters some errors. I will list how I can debug and fix them.
The main content of this article is to use the Sonic engine to enable Flarum to search Chinese as well.
In my Flarum, the search module isn’t perfect enough so far, almost all the discussions are using Chinese, so the default search module doesn’t work. Here, in this section, I primarily focus on utilizing the Sonic extension to implement Chinese text search. In my case, the server-side encounters some errors. I will list how I can debug and fix them.
Extensions
Here is the plugin link.
https://discuss.flarum.org/d/28826-flarum-sonic
Install Sonic env in Ubuntu 22.04.3
My sever is micro tier, so I will choose docker to install sonic env. If you are unfamiliar with docker, you can consider it’s a standalone container/server. In this container, you can install everything just as you would on a server.
Install Docker
To install Docker on Ubuntu, you can follow these steps:
- Update your system’s package index
- Install the required dependencies
- Add the official Docker GPG key
- Set up the stable Docker repository (Replace $(lsb_release -cs) with the codename of your Ubuntu release if it’s not automatically detected.)
- Install Docker
- Verify that Docker is installed
|
|
when run sudo docker --version
you will see the version in the terminal
Install Sonic in docker
v1.4.8 is the latest version so far, you can replace any version you want
|
|
Now, create a config file for snoic, I set up config.cfg under my home folder, the path it’s up to you.
you need root permission.
|
|
in the config.cfg, just copy paste the default content the developer provided
|
|
Then, save the file and exit.
Install Sonic extension
|
|
Navigate to you admin panel, switch on the extension, no need to change anything, just save it.
Running Sonic
In the server, switch to root permission to run:
|
|
Then, navigate to fluarm folder run:
|
|
If it prints the “xxx successfully!”, you are lucky, all the steps have done! We can highlight the keyword
|
|
Error: PHP Notice: fwrite(): send failed with errno=32 Broken pipe
If there are tons of error print it out, like this, well, let’s debug it.
✨ Copy same env
It’s quite complex, to be honest. I created another instance and RDS to test whether the issue is due to my server environment or something else. Additionally, I don’t want to impact my current production environment.
Oh, also need to create a new security group, and open port 80, 22(If you don’t mind the security issue in test env, also can allow all traffic)
Just make the version is the same as the production env.
Follow my previous blog, I installed php env, composer, and flarum.
Don’t forget to edit composer.json file, and delete composer.lock. Then install again. The CLI is
|
|
After that, In RDS section, need to set up EC2 connection.
Also I exported my sql from RDS, and imported my test mysql env.
Debug in Test env
Now, follow the snoic installation. In snoic source code, we can find the entry. I don’t understand PHP code, but I know where the error is printed out. The logic is to retrieve all the public posts and push them somewhere. In this code, I need to find where the first error occurs.
I changed the code directly, added a break inside the loop, and printed every content retrieved.
|
|
I received 700 normal contents, and then it jumped out of the loop. Now I see that the error part is very long and large because one of the users typed a lot of content in one section.
I have two solutions: split the content or simply ignore long content. I choose the latter one, as it is easier, albeit at the cost of some search accuracy
|
|
I already know the post ID for the long content, so I skipped those. Then, I ran the CLI in the Flarum path:
|
|
All the test pass!
I also try to split the content, but didn’t work😭😭😭, can anyone tell me the reason?
|
|