mattie-bundle for Strapi

website·Indexed 31 days ago

https://mattie-bundle.mattiebelt.com/

A bundle of features for Strapi v4, including a search plugin that utilizes a provider system (such as Algolia) to index content and enable fast search functionality.

Tokens
1.3K
Snippets
7
Records
10
Agent score
50%

What's inside mattie-bundle

  1. Overview of Mattie Bundle Search capabilities for Strapi v4

    The Mattie Bundle provides a search plugin for Strapi v4 that allows developers to index Strapi-managed content into third-party search providers (such as Algolia) to enable instant search results on a frontend.
  2. Set up Algolia search indexing in Strapi v4

    To integrate Algolia search indexing into a Strapi v4 application using the mattie-bundle, follow these steps:

    1. Create a Strapi App: Initialize a new project.
    2. Define Content: Create a collection type (e.g., Post) via the Content-Type Builder.
    3. Algolia Setup: Obtain your Application ID and Admin API Key from the Algolia dashboard (Settings > Team and Access > API Keys).
    4. Environment Configuration: Add the Algolia credentials to your .env file.
    5. Install Dependencies: Install the search plugin and the Algolia provider.
    6. Plugin Configuration: Configure the plugin in config/plugins.js to specify the provider and the content types to be indexed.
    7. Index Content: Create, save, and publish an entry in the Strapi Content Manager to trigger indexing to Algolia.
    # Install the Search plugin and Algolia provider
    yarn add @mattie-bundle/strapi-plugin-search @mattie-bundle/strapi-provider-search-algolia
    # OR
    npm install @mattie-bundle/strapi-plugin-search @mattie-bundle/strapi-provider-search-algolia
  3. Install the Strapi Search Plugin

    Install the @mattie-bundle/strapi-plugin-search package as a dependency in your Strapi project. After installation, you must rebuild the Strapi admin panel to apply the changes.
    # Install via yarn
    yarn add @mattie-bundle/strapi-plugin-search
    
    # OR install via npm
    npm install @mattie-bundle/strapi-plugin-search
    
    # Rebuild admin panel (yarn)
    yarn build --clean
    
    # Rebuild admin panel (npm)
    npm run build -- --clean
  4. Install the Algolia search provider for Strapi

    To use Algolia as the search service for the Strapi search plugin, install the @mattie-bundle/strapi-provider-search-algolia package as a project dependency.
    # Using yarn
    yarn add @mattie-bundle/strapi-provider-search-algolia
    
    # Using npm
    npm install @mattie-bundle/strapi-provider-search-algolia
  5. Configure the Search Plugin via plugins.js

    The Search Plugin is configured in ./config/plugins.js using the Strapi v4 plugin configuration format. It allows you to define the search provider, global indexing settings, and specific content types to be indexed.
    module.exports = ({ env }) => ({
      search: {
        enabled: true,
        config: {
          provider: 'algolia', // Required: Name of the provider
          providerOptions: {
            apiKey: env('ALGOLIA_PROVIDER_ADMIN_API_KEY'),
            applicationId: env('ALGOLIA_PROVIDER_APPLICATION_ID'),
          },
          prefix: 'custom-prefix_', // Optional: Prefix for all indexes
          excludedFields: ['createdAt', 'createdBy', 'updatedBy'], // Optional: Fields to skip indexing
          debug: true, // Optional: Enable debug logs
          contentTypes: [
            {
              name: 'api::podcast.podcast', // Required: Content type UID
              index: 'podcast', // Optional: Index name (defaults to content type name)
              fields: ['title', 'description'], // Optional: Specific fields to index
            },
          ],
        },
      },
    });
  6. Map multiple content types to a single search index

    To aggregate multiple Strapi content types into a single search index (e.g., a 'global-search' index), assign the same index value to multiple entries in the contentTypes array.
    contentTypes: [
      {
        name: 'api::podcast.podcast',
        index: 'global-search',
      },
      {
        name: 'api::episode.episode',
        index: 'global-search',
      },
    ],
  7. Configure the Algolia search provider in Strapi

    Configure the Algolia provider in the search plugin configuration using the provider and providerOptions keys. The apiKey must be either the Algolia Admin API Key or a custom key with search, addObject, and deleteObject ACL permissions.
    // ./config/plugins.js
    module.exports = ({ env }) => ({
      search: {
        enabled: true,
        config: {
          provider: 'algolia',
          providerOptions: {
            apiKey: env('ALGOLIA_PROVIDER_ADMIN_API_KEY'),
            applicationId: env('ALGOLIA_PROVIDER_APPLICATION_ID'),
          },
          // ...
        },
      },
    });
  8. Configure the Algolia Search provider in Strapi

    Configure the @mattie-bundle/strapi-plugin-search plugin in the ./config/plugins.js file. You must specify the algolia provider, provide the API credentials via environment variables, and list the content types (using their Strapi UID) that should be indexed.
    // .env
    ALGOLIA_PROVIDER_APPLICATION_ID=your_app_id
    ALGOLIA_PROVIDER_ADMIN_API_KEY=your_admin_api_key
    
    // ./config/plugins.js
    'use strict';
    
    module.exports = ({ env }) => ({
      search: {
        enabled: true,
        config: {
          provider: 'algolia',
          providerOptions: {
            apiKey: env('ALGOLIA_PROVIDER_ADMIN_API_KEY'),
            applicationId: env('ALGOLIA_PROVIDER_APPLICATION_ID'),
          },
          contentTypes: [{ name: 'api::post.post' }],
        },
      },
    });
  9. Algolia provider configuration options

    PropertyDescriptionType
    providerName of the provider, must be 'algolia'.String (required)
    providerOptionsProvider specific options.Object (required)
    providerOptions.apiKeyAlgolia API key (Admin API Key or custom key with search, addObject, deleteObject ACLs).String (required)
    providerOptions.applicationIdAlgolia application ID.String (required)