dimitrov-adrian / directus-extension-searchsync

Simple Directus 9 extension that sync content with remote search engine.
MIT License
116 stars 27 forks source link

Feat/flatten objects #2

Closed Jonesus closed 3 years ago

Jonesus commented 3 years ago

Adds a new option to flatten data before indexing, for easier handling of nested objects, for example translated data.

Flattens the Directus data keys to dot notation, for example:

{
  name: 'helga',
  profession: {
    id: 1,
    title: 'driver'
  },
  translations: [
    {
      lang: 'en',
      title: 'driver'
    },
    {
      lang: 'fr',
      title: 'chauffeur'
    }
  ],
}

Transforms into

{
  name: 'helga',
  profession.id: 1,
  profession.title: 'driver',
  translations.0.lang: 'en',
  translations.0.title: 'driver',
  translations.1.lang: 'fr',
  translations.1.title: 'chauffeur',
}

It's a bit awkward for arrays but it works and it's reasonably painless to parse the search results back into a similar object that was in Directus

This branch is based on the RC update branch (https://github.com/dimitrov-adrian/directus-extension-searchsync/pull/1), so there's an extra commit before the main contents of this pr :)