Search Algolia indices from Postgres databases.
- PostgreSQL
- available pg_config, this extension uses PGXS
- cJSON
- cURL
- Make
- Build and install the extension:
cd alpg;
make;
- Create the extension in your selected database. Make sure that your user has the right privileges.
CREATE EXTENSION alpg;
- Check whether the extension has been installed correctly.
\dx alpg
Should return alpg
as one of available extensions.
Before running extension's functions you need to set up environment variables alpg.api_key
and alpg.app_id
.
Remember to set those values for every session you use since SET is only persistent
to session or transaction. If even one of those values is undefined, the function will throw.
search_algolia(
index_name text,
search_string text,
attributes_to_retrieve text,
page integer DEFAULT 0,
per_page integer DEFAULT 30
) returns setof (document jsonb)
where:
index_name
requiredsearch_string
requiredattributes_to_retrieve
comma-separated list of document fields, requiredpage
defaults to 0, must be in the range of (0, n>per_page
defaults to 30, must be in the range of (1,1000>document
jsonb objects representing the received documents, one for each row, json fields can be accessed via the '->' operator