Does anyone know of a good tutorial for creating a webhook that syncs Prismic data with Algolia?
I know it can be done by using a webhook that's triggered on content change but I've had trouble finding a walkthrough on how that webhook is created in the first place. I'd appreciate if someone knows of a tutorial.
@Phil Can you bump this up for us? Given the fact that Prismic's full text search seems to have a permanent seat on the struggle bus, it'd be nice to get some help in hooking up the webhook to Algolia.
I'm assuming that (given the fact that prismic.io uses Algolia), this integration has been done, so even if we could get some pointers about how that integration happened, that'd be swell. Thanks!
Hey @jason.clark. Here are some recommendations from our DevX team!
Whenever a website is rebuilt, send all documents from the Prismic repository to Algolia for indexing. This can take the form of a script that runs before or after the website’s primary npm run build script. The script should perform the following:
Query all Prismic documents. If only certain documents map to pages within the website, only query those documents.
Assign an objectID property to each document (required by Algolia). The Prismic document’s id property should be sufficient depending on your Algolia index’s setup
Assign a url mapping the document to a URL within the website. If the website uses a Prismic Link Resolver to generate URLs, that Link Resolver should be used in this step.
Prune any document properties that should not be indexed. For example, the type, href, first_publication_date, last_publication_date, slugs, linked_documents, lang, and alternate_languages properties may cause issues when searching.
Push the documents to an Algolia index.
The index is now available for searching via one of Algolia’s packages.
I wrote this article that explains pretty much the above process but with an agnostic approach and code examples (not relying on Prismic):