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 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 or Self-hosting. 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:

  1. 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.

  1. In the Typesense app page, enter your Typesense credentials from the previous step.

  2. 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.

4. Click Save to confirm the settings.

Connect to Typesense

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.

Note

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 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 types.

Prepr field types
Typesense field types
Textstring
Booleanbool
Floatfloat
Integerint32, int64
Dynamic contentstring

Note: All text fields in the Dynamic content field will be merged into a single string.
Content referenceJSON object

Note: It only includes an ID and title of a content item.
AssetJSON object

Note: It only includes an asset URL.
Tagstring[]

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 ​​for your programming language. After setting up the client, you can initialize and connect it to Typesense.

For examples on how to search records in your collections, check out the Searching for books doc.

Also, check out how to build a search UI with Typesense.

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"
   }
}

Important

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 Authentication.