9adc7884ff65bc9ede3f19915c1402add16072c1
[akkoma] / docs / configuration / search.md
1 # Configuring search
2
3 {! backend/administration/CLI_tasks/general_cli_task_info.include !}
4
5 ## Built-in search
6
7 To use built-in search that has no external dependencies, set the search module to `Pleroma.Activity`:
8
9 > config :pleroma, Pleroma.Search, module: Pleroma.Activity
10
11 While it has no external dependencies, it has problems with performance and relevancy.
12
13 ## Meilisearch
14
15 Note that it's quite a bit more memory hungry than PostgreSQL (around 4-5G for ~1.2 million
16 posts while idle and up to 7G while indexing initially). The disk usage for this additional index is also
17 around 4 gigabytes. Like [RUM](./cheatsheet.md#rum-indexing-for-full-text-search) indexes, it offers considerably
18 higher performance and ordering by timestamp in a reasonable amount of time.
19 Additionally, the search results seem to be more accurate.
20
21 Due to high memory usage, it may be best to set it up on a different machine, if running pleroma on a low-resource
22 computer, and use private key authentication to secure the remote search instance.
23
24 To use [meilisearch](https://www.meilisearch.com/), set the search module to `Pleroma.Search.Meilisearch`:
25
26 > config :pleroma, Pleroma.Search, module: Pleroma.Search.Meilisearch
27
28 You then need to set the address of the meilisearch instance, and optionally the private key for authentication.
29
30 > config :pleroma, Pleroma.Search.Meilisearch,
31 > url: "http://127.0.0.1:7700/",
32 > private_key: "private key"
33
34 Information about setting up meilisearch can be found in the
35 [official documentation](https://docs.meilisearch.com/learn/getting_started/installation.html).
36 You probably want to start it with `MEILI_NO_ANALYTICS=true` and `MEILI_NO_CENTRY=true` environment variables,
37 to disable analytics.
38
39 ### Private key authentication (optional)
40
41 To set the private key, use the `MEILI_MASTER_KEY` environment variable when starting. After setting the _master key_,
42 you have to get the _private key_, which is actually used for authentication.
43
44 === "OTP"
45 ```sh
46 ./bin/pleroma_ctl search.meilisearch show-private-key <your master key here>
47 ```
48
49 === "From Source"
50 ```sh
51 mix pleroma.search.meilisearch show-private-key <your master key here>
52 ```
53
54 This is the key you actually put into your configuration file.
55
56 ### Initial indexing
57
58 After setting up the configuration, you'll want to index all of your already existsing posts. Only public posts are indexed. You'll only
59 have to do it one time, but it might take a while, depending on the amount of posts your instance has seen. This is also a fairly RAM
60 consuming process for `meilisearch`, and it will take a lot of RAM when running if you have a lot of posts (seems to be around 5G for ~1.2
61 million posts while idle and up to 7G while indexing initially, but your experience may be different).
62
63 To start the initial indexing, run the `index` command:
64
65 === "OTP"
66 ```sh
67 ./bin/pleroma_ctl search.meilisearch index
68 ```
69
70 === "From Source"
71 ```sh
72 mix pleroma.search.meilisearch index
73 ```
74
75 This will show you the total amount of posts to index, and then show you the amount of posts indexed currently, until the numbers eventually
76 become the same. The posts are indexed in big batches and meilisearch will take some time to actually index them, even after you have
77 inserted all the posts into it. Depending on the amount of posts, this may be as long as several hours. To get information about the status
78 of indexing and how many posts have actually been indexed, use the `stats` command:
79
80 === "OTP"
81 ```sh
82 ./bin/pleroma_ctl search.meilisearch stats
83 ```
84
85 === "From Source"
86 ```sh
87 mix pleroma.search.meilisearch stats
88 ```
89
90 ### Clearing the index
91
92 In case you need to clear the index (for example, to re-index from scratch, if that needs to happen for some reason), you can
93 use the `clear` command:
94
95 === "OTP"
96 ```sh
97 ./bin/pleroma_ctl search.meilisearch clear
98 ```
99
100 === "From Source"
101 ```sh
102 mix pleroma.search.meilisearch clear
103 ```
104
105 This will clear **all** the posts from the search index. Note, that deleted posts are also removed from index by the instance itself, so
106 there is no need to actually clear the whole index, unless you want **all** of it gone. That said, the index does not hold any information
107 that cannot be re-created from the database, it should also generally be a lot smaller than the size of your database. Still, the size
108 depends on the amount of text in posts.