Skip to content

allow multiple indexers for one collection#1

Open
T-Mike wants to merge 1 commit into
dawid-napora:masterfrom
T-Mike:multiple-indexes-per-collection
Open

allow multiple indexers for one collection#1
T-Mike wants to merge 1 commit into
dawid-napora:masterfrom
T-Mike:multiple-indexes-per-collection

Conversation

@T-Mike

@T-Mike T-Mike commented Aug 7, 2024

Copy link
Copy Markdown

Hi,
Just added meilisearch to a new directus project and your work saved me a lot of time!
Because the project I work on is multilingual, I needed to be able to make an index per collection per language.
i.e : collection1_en, collection1_fr, collection2_en, collection2_fr etc...
The most logical way I could think of was change the config file structure by replacing collections key for indexes.
Let's take an example:

const config = {
  server: {
      type: "meilisearch",
      host: "http://meilisearch:7700",
      key: "mykey",
  },
  reindexOnStart: true,
  batchLimit: 100,
  indexes: {
    designer_en: {
      collectionName: 'designer',
      filter: {
          status: "published",
      },
      fields: ['id', 'some_field'],
      transform: (item, { flattenObject, striptags }) => {
        // do some things
        return item
      }
    },
    designer_fr: {
      collectionName: 'designer',
      filter: {
          status: "published",
      },
      fields: ['id', 'some_other_field'],
      transform: (item, { flattenObject, striptags }) => {
        // do some other things
        return item
      }
    }
  }
}

There are two indexes, designer_en and designer_fr and they are completely separated. Meaning you can do whatever you want with each one.

The code provided works, I did not see any bug related to it but it is not battle tested.

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant