Before you begin
Make sure you have:- An Algolia account. Create one for free if you don’t already have one.
- A Supabase project with the sample data in a
public.appareltable. Download the Algolia apparel sample data and follow Supabase’s data import instructions. UseobjectIDas the table’s primary key.
Set up the Supabase connector
Create a source, transformation, destination, and synchronization task.1
Choose the Supabase connector
Go to the Algolia dashboard and select your Algolia application.Open the Connectors page.Find Supabase and select Connect.
Under Quick setup, select Connect Supabase.
2
Configure the Supabase source
For Select a project,
choose the project containing the
public.apparel table.
The connector copies Host, Port, Session Pooler Port, Database Name, Username, and Password values from your Supabase project.For SSL modes, select Prefer.In Connector name,
enter Quickstart products Supabase source,
then select Create source.3
Transform the records
This transformation adds a Select Save.
price_range attribute to each record.
After the connector indexes your records, you can display price_range or configure it as a facet.Select Transform using the code editor and replace the placeholder Transformation code with this function:JavaScript
4
Choose the destination index
Under Configure your destination,
select Create a new destination.Under Search,
enter
quickstart-products as the index name.5
Create the destination
Under Index credentials,
select Create one for me.To use an existing API key,
choose one with the
addObject, deleteIndex, and editSettings
access control list permissions.In Name,
enter Supabase quickstart products destination,
then select Create destination.6
Create and run an on-demand synchronization task
Under Configure your task,
select On demand and clear Scheduled.Select Full reindexing.Select
apparel as the source table.
Select all columns.
For ObjectID, select objectID.Select Create task,
then Run,
and wait for the task to finish.7
Verify the indexed records
Open the
quickstart-products index in the Algolia dashboard.Check that the index contains the imported product records,
with attributes such as title, description, product_type,
price, price_range, and showcase_image.You can use this index as the data source for
Build your first search experience.Before you build the UI,
configure
product_type as an attribute for faceting
in the quickstart-products index.Deploy a search app
To search your Supabase records, deploy the React InstantSearch product search app. It uses the Vercel integrations for Algolia and Supabase to create your Algolia app and Supabase database and add their credentials to your project. The README walks you through loading the sample data, creating the connector, and configuring the index.Deploy with Vercel
Create the app, your Algolia application, and a Supabase database in Vercel.
Explore source code
Browse the Supabase product search app on GitHub.
Index your own Supabase data
To index your own data:- Use a populated Supabase table or view that the connector credentials can read.
- Follow the quickstart steps to create the source, destination, and task. Replace the sample project, table, credentials, and destination index with your own values.
- Review or remove the sample transformation so that it matches your record structure. When you configure the task, select the columns you want to include in your Algolia records.
- Select the column to use as the Algolia
objectID. This column must be present in every row, and its value must be unique and stable.
Supabase database credentials
The quickstart uses the database settings imported from your Supabase project. For your own data, create a dedicated Postgres login role for the connector. Grant the role permission to:- Connect to the database.
- Use the schema that contains the source data.
- Run
SELECTqueries on each table or view the connector needs to read.
SELECT policy that lets the connector role read the rows you want to index.
For more information, see Postgres roles and
Row Level Security.
Configure the connector username
For a shared session pooler connection, replacepostgres in the username with the dedicated connector role name.
Keep the project reference after the period character: ..
For example, for a connector role named algolia_connector,
replace postgres.PROJECT_REFERENCE with algolia_connector.PROJECT_REFERENCE.
Combine data with a Postgres view
An Algolia record can combine data from several Supabase tables. For example, a product record might combine product details with review ratings and recent order data. If your source data spans several tables, create a Postgres view that joins and aggregates the required data. Then, select the view as the source when you configure the synchronization task. Make sure each row in the view includes a unique, stable column that you can use as the AlgoliaobjectID.
The following example assumes you have an apparel and a reviews table with id, product_id, and rating columns.
It creates a view that combines their data.
SQL
Transformations
Use transformations to add computed attributes or change values before the connector indexes your records. To use a transformed attribute for search, faceting, or ranking, update the relevant index settings, such assearchableAttributes, attributesForFaceting, or customRanking.
Test transformations with repeated task runs.
Transformations that read from and write to the same attribute,
or extract a value and then delete the source attribute,
can produce different results when the task runs again.
Synchronization schedule
After you create a task, you can edit it in the Algolia dashboard to choose when the connector runs:- On demand. Run the connector manually.
- Scheduled. Select a predefined schedule or enter a custom cron expression.
0 */4 * * * and all predefined schedules, such as Every day,
Algolia offsets each task’s scheduled run time by a fixed amount to distribute task executions over time.
A task uses the same offset for every run.
The offset is always shorter than the interval between runs.
For example, 0 */4 * * * schedules a task every four hours, starting at 00:00 UTC.
With an offset of 2 hours and 37 minutes, the task would instead run at 02:37, 06:37, and 10:37 UTC.
To schedule a task at specific times, list the hours in the cron expression.
For example, 0 0,4,8,12,16,20 * * * schedules a task at 00:00, 04:00, 08:00, 12:00, 16:00, and 20:00 UTC.
Indexing strategy
You can choose how the connector updates your index. For information about full reindexing, full record updates, and partial record updates, see Data synchronization strategies.Allow Algolia IP addresses
If your source restricts access by IP address, allow these Algolia IP addresses:104.196.103.17335.234.69.129