Skip to content

Commit 1543ff0

Browse files
committed
feat: add docs for Typesense search backend
Document how to get started with the new Typesense search backend, and some tips about clustered Typesense and using a web dashboard. Private-ref: https://tasks.opencraft.com/browse/BB-10458
1 parent 5b9e601 commit 1543ff0

1 file changed

Lines changed: 175 additions & 0 deletions

File tree

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
.. _Use Typesense search backend:
2+
3+
Use Typesense search backend
4+
############################
5+
6+
.. tags:: site operator, how-to
7+
8+
.. note::
9+
10+
Typesense search support has not been included in a release yet. Stay tuned!
11+
12+
`Typesense <https://typesense.org/>`_ is supported for the following search areas:
13+
14+
* Course info (course search on the Discover New page)
15+
* Courseware (course content search)
16+
* Forum (threads and comments)
17+
18+
Typesense is supported as both a single node and as a cluster for high availability (HA).
19+
This is not the default though; Meilisearch is the default search backend.
20+
21+
Getting started
22+
***************
23+
24+
See below for how to start using Typesense with your Open edX instance, depending on whether you use Tutor or not:
25+
26+
Tutor
27+
=====
28+
29+
If you use Tutor, you can install the `tutor-contrib-typesense`_
30+
plugin, which will automatically deploy a single node Typesense instance
31+
and configure the platform to use it.
32+
33+
.. note::
34+
35+
This plugin does not support deploying Typesense as a HA cluster. If you require a cluster, please follow the manual configuration section below.
36+
37+
#. Install the plugin:
38+
39+
.. code-block:: shell
40+
41+
pip install -e https://github.com/open-craft/tutor-contrib-typesense
42+
tutor plugins enable typesense
43+
44+
#. Configure if required. For most cases, the defaults will be fine. Available configuration is documented on `the plugin's readme <https://github.com/open-craft/tutor-contrib-typesense?tab=readme-ov-file#configuration>`_.
45+
46+
If you require custom configuration, set them using Tutor, for example:
47+
48+
.. code-block:: shell
49+
50+
tutor config save --set TYPESENSE_COLLECTION_PREFIX=my_instance_
51+
52+
#. Initialise the plugin - some examples:
53+
54+
.. code-block:: shell
55+
56+
# if an existing k8s deployment
57+
tutor k8s do init --limit=typesense
58+
59+
# if launching a devstack
60+
tutor dev launch
61+
62+
#. Reindex content - if this is an existing deployment with content already, you will need to manually run a reindex (the Typesense indexes are created automatically):
63+
64+
.. code-block:: shell
65+
66+
# reindex courseware content and course info
67+
tutor dev exec cms -- python manage.py cms reindex_course --active
68+
69+
# reindex forum threads and comments
70+
tutor dev exec lms -- python manage.py lms rebuild_forum_indices
71+
72+
#. Finally, to enable course content search on the frontend, create and enable a waffle flag named ``courseware.mfe_courseware_search``. You can do this from the LMS Django admin page, waffle flags section.
73+
74+
Manual configuration
75+
====================
76+
77+
If you aren't using Tutor, here are instructions for getting started manually.
78+
79+
#. Deploy an instance of Typesense. See the `Typesense installation guide <https://typesense.org/docs/guide/install-typesense.html>`_ for more information.
80+
81+
#. Create an API key. See the Typesense `API Keys doc <https://typesense.org/docs/latest/api/api-keys.html>`_ for more information.
82+
Optionally, for extra security, you can scope the API key permissions to a custom collection prefix. This prefix can be configured for the Open edX platform in the following step (the ``TYPESENSE_COLLECTION_PREFIX`` setting).
83+
For example:
84+
85+
.. code-block:: shell
86+
87+
curl -X POST 'http://localhost:8108/keys' \
88+
-H 'Content-Type: application/json' -H 'X-TYPESENSE-API-KEY: mysecretadminkey' \
89+
--data-binary '{
90+
"value": "mysecretapikeyvalue",
91+
"description": "API key for my Open edX instance",
92+
"actions": ["*"],
93+
"collections": ["^openedx_.*"]
94+
}'
95+
96+
97+
#. Set the following Django settings for LMS and CMS:
98+
99+
.. code-block:: python
100+
101+
# Enable the Typesense backend.
102+
TYPESENSE_ENABLED = True
103+
104+
# Set the API key for authenticating to Typesense.
105+
TYPESENSE_API_KEY = "your-secret-api-key-for-typesense"
106+
107+
# Set the internal urls where the LMS/CMS can reach the Typesense API.
108+
# If Typesense is deployed as a cluster, provide the urls to all nodes here.
109+
TYPESENSE_URLS = ["https://typesense-1.example.com:8108", "https://typesense-2.example.com:8108"]
110+
111+
# The prefix that the backend should use for all collections (you can scope the API key permissions to this prefix for security).
112+
# This is useful if the Typesense instance is shared with other software.
113+
TYPESENSE_COLLECTION_PREFIX = "openedx_"
114+
115+
# Optional: if you need to override the forum search backend module for testing
116+
#FORUM_SEARCH_BACKEND = "forum.search.typesense.TypesenseBackend"
117+
118+
# Optional: if you need to override the course search backend module for testing
119+
#SEARCH_ENGINE = "search.typesense.TypesenseEngine"
120+
121+
122+
#. Reindex content - if this is an existing deployment with content already, you will need to manually run a reindex (the Typesense indexes are created automatically):
123+
124+
.. code-block:: shell
125+
126+
# In the CMS environment: reindex courseware content and course info
127+
python manage.py cms reindex_course --active
128+
129+
# In the LMS environment: reindex forum threads and comments
130+
python manage.py lms rebuild_forum_indices
131+
132+
#. Finally, to enable course content search on the frontend, create and enable a waffle flag named ``courseware.mfe_courseware_search``. You can do this from the LMS Django admin page, waffle flags section.
133+
134+
135+
Clustered Typesense
136+
*******************
137+
138+
Some notes regarding running Typesense in a cluster, for a HA setup.
139+
140+
* For clustered Typesense, it's best to provide urls to all the nodes to ``TYPESENSE_URLS``, rather than putting it behind a load balancer.
141+
This allows the Typesense client to manage load balancing and fallbacks itself.
142+
* Be careful when running a Typesense cluster on Kubernetes, as there can be issues related to how consensus is implemented and that Kubernetes pods don't necessarily have static IP addresses. See `typesense/typesense#465 <https://github.com/typesense/typesense/issues/465>`_ and `typesense/typesense#2049 <https://github.com/typesense/typesense/issues/2049>`_ for more information.
143+
144+
145+
Typesense web dashboard
146+
***********************
147+
148+
Typesense doesn't come with an official web dashboard,
149+
but there is a community dashboard developed at https://github.com/bfritscher/typesense-dashboard.
150+
You can visit it directly on the web without installing at https://bfritscher.github.io/typesense-dashboard/.
151+
152+
For example, to connect to a Typesense server from a local Tutor devstack using the Typesense plugin,
153+
visit the web dashboard url, and enter the following details at the login screen:
154+
155+
* Api Key: (use the output from running ``tutor config printvalue TYPESENSE_API_KEY``)
156+
* protocol: ``http``
157+
* host: ``localhost``
158+
* port: ``8108``
159+
* path: (leave blank)
160+
161+
162+
.. seealso::
163+
164+
:ref:`Enable edX Search`
165+
166+
167+
**Maintenance chart**
168+
169+
+--------------+-------------------------------+----------------+--------------------------------+
170+
| Review Date | Working Group Reviewer | Release |Test situation |
171+
+--------------+-------------------------------+----------------+--------------------------------+
172+
| | | | |
173+
+--------------+-------------------------------+----------------+--------------------------------+
174+
175+
.. _tutor-contrib-typesense: https://github.com/open-craft/tutor-contrib-typesense/

0 commit comments

Comments
 (0)