Typesense
This integration allows you to use the Typesense search engine for an optimized search experience on Prepr content in your web app.
The Typesense integration is available as a paid option on top of your regular subscription. Please contact our Sales team (opens in a new tab) for more details.
Introduction
Prepr supports integration with Typesense, an open source, typo tolerant search engine. It enables your Prepr content items to be indexed using the Typesense algorithm, maximizing the search speed and content discovery in your web app.
Step 1: Get the API credentials from your Typesense app
To connect Prepr to Typesense, you need a valid API key to create Typesense collections and index documents in collections. Typesense uses these credentials to identify your Prepr application and control access to the Typesense API.
There are two options to install Typesense, either with Typesense Cloud (opens in a new tab) or Self-hosting (opens in a new tab). If you choose to do self-hosting, make sure the host is public for Prepr to have access.
Once Typesense is installed, generate the API key according to the instructions in the Typesense installation docs. You'll need the Admin API key, Host, Protocol and Port when setting up the Typesense integration in Prepr.
Step 2: Connect Prepr to Typesense
Now that you have the required credentials, you can set up the Typesense integration in Prepr as follows:
- Go to Settings → Integrations and choose Typesense. Click the Activate button.
If you do not have access to the Typesense yet, click Request activation. Our Sales team will get in touch with you shortly to activate your request.
-
In the Typesense app page, enter your Typesense credentials from the previous step.
-
Select the models you want to sync to Typesense and map them to each Typesense collection. You can specify the existing collections you already have in your Typesense app, or you can provide new names from within Prepr. In the latter case, the collections with the relevant names will be created automatically once the data is synced to Typesense. Read more about the Typesense collections (opens in a new tab).
-
Click Save to confirm the settings.
That's it. You’ve connected Prepr to Typesense. From now on, Prepr will automatically keep syncing your content items to Typesense for indexing.
When a new content item is published, a new document is added to the related collection in Typesense. Any changes to the published content item result in updating the corresponding Typesense document. Once the content item is unpublished, the Typesense document will be deleted.
So you can be sure your data is always-in-sync, and that the most up-to-date content is available to your web app visitors.
Changes to the Schema, in other words, the content item structure won't be synced to Typesense automatically. In this case, you must run the sync manually. Please read more on how to sync schema updates to Typesense.
Indexed field types
Before sending your content item data to Typesense, Prepr automatically transforms it into a JSON format (opens in a new tab) that Typesense recognizes. Once data is prepared and synced, the corresponding documents are added to a Typesense collection you specified in Step 2.
The following table shows indexed Prepr field types and the corresponding Typesense field types (opens in a new tab) types.
Prepr field types | Typesense field types |
---|---|
Text | string |
Boolean | bool |
Float | float |
Integer | int32, int64 |
Dynamic content | string Note: All text fields in the Dynamic content field will be merged into a single string. |
Content reference | JSON object Note: It only includes an ID and title of a content item. |
Asset | JSON object Note: It only includes an asset URL. |
Tag | string[] |
Step 3: Connect your front end to Typesense
Now that your Prepr data is indexed with Typesense, you’re ready to implement Typesense in your web app.
Follow the Typesense instructions to install a client (opens in a new tab) for your programming language. After setting up the client, you can initialize and connect it to Typesense (opens in a new tab).
For examples on how to search records in your collections, check out the Searching for books (opens in a new tab) doc.
Also, check out how to build a search UI with Typesense (opens in a new tab).
How to sync existing content and schema updates to Typesense
The steps above allow you to index all new content created after enabling the Typesense integration. If you need to index any content you already have, or after a schema update, you need to run the sync action manually.
To sync content items to Typesense manually, you must call the given Prepr endpoint and specify a model ID, which you can find under Schema → Model → → Copy Model ID.
Content items will be synced in batches of 1,000 in approximately 2 seconds for each batch. The overall time depends on the number of content items you have.
The following API request will sync content items to Typesense:
GET: https://api.eu1.prepr.io/publications/typesense/sync
{
"model": {
"id": "YOUR_MODEL_ID"
}
}
Make sure to create an access token with the REST API scopes content_items
and content_items_publish
and bind a user to this token under Settings → Access tokens.
Please note that access tokens with write permissions must not be visible client-side. Read more in the Mutation API Authorization doc.
If you have any questions, please contact our Support team (opens in a new tab).
Was this article helpful?
We’d love to learn from your feedback