Full-Text Search in Database For Mastodon
Categories: [ IT ]
I run my own instance of Mastodon on a server with little memory, i.e. not enough to be able to run ElasticSearch in addition to Mastodon. This means that I cannot do a full-text search on my toots (which would have come handy from time to time).
As an alternative solution, I have implemented a full-text search on database. It is most probably not suitable to use on a large instance, as the implementation uses an SQL query with multiple LIKE conditions ORed together. That's not the most efficient way of querying a database, but for a small enough number of statuses (40k at the moment), it's probably good enough.
This feature is (and will probably forever remain) experimental, but if you
want to give it a try, and assuming that you have installed Mastodon from
Git like me
in /home/mastodon/live
and run v4.1.0, here's how to do it.
$ cd /home/mastodon/live $ git remote add db_search https://weber.fi.eu.org/software/mastodon $ git fetch db_search $ git checkout v4.1.0+db_search.1 $ echo "FULL_TEXT_DB_SEARCH=true" >> .env.productionThen restart the mastodon-web service by running as root:
systemctl restart mastodon-web.service
Reload the mastodon Web UI in your web browser. When you click on the search box, you should now see a message like “Simple text returns posts you have written…” and searching with words you know you have written should display matching toots.
EDIT: I expanded the search to also consider the descriptions of media attachments. The updated version is available as tag v4.1.0+db_search.1.