Algolia Search integration with 8base and Gatsby

Hey @Bri - okay, this is what I would do if you want to use Algolia.

  1. Decide on what record/resource in 8base you want to perform search against. For example, let’s say you’re storing article records in an 8base table called Articles and you want to perform search across the Title and description fields and author relationship.

  2. You create an after.trigger in 8base that runs on Article.create (and later Article.update and Article update…but ignore that for now) that creates a new entry in you Angolia Articles.index whenever a new article is created.

Something like:

export default function (event, ctx) {
  const algoliasearch = require("algoliasearch");

  const client = algoliasearch(
    process.env.Your_Angolia_Application_ID, 
    process.enc.Your_Angolia_Admin_API_Key
  );

  const index = client.initIndex("8base_articles");

  await index.saveObject({
    objectID: event.data.id,
    title: event.data.title,
    description: event.data.description,
    author: `${event.data.author.connect.firstName} ${event.data.author.connect.lastName}`
  })

  return {
    data: {
      ...event.data
    }
  }
}
  1. When performing search in your front-end application, utilize the Angolia API and search against this index so that you’re benefiting from the highly performant search queries.

  2. When a search result is selected, use the returned result ID to then make an Query to the 8base GraphQL API for the full record and any related records.

LMK if this helps.

Sebastian

1 Like

That sounds good to me @sebastian.scholl. And yes, it was helpful to see it laid out like that, thanks for taking the time to pull it together.

My pleasure! Good luck and please keep using this thread if questions pop up.