Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom rules on fields and Published conditions #70

Open
thiboot opened this issue Mar 18, 2022 · 1 comment
Open

Custom rules on fields and Published conditions #70

thiboot opened this issue Mar 18, 2022 · 1 comment

Comments

@thiboot
Copy link

thiboot commented Mar 18, 2022

Hello,

With the old version of Algolia Hook i was able to do some customizations on object fields and trigger the record only on publish.

'use strict';

const index = 'songs';

const songToAlgolia = ({id, title, slug, content, historicalFacts, illustration, audio, categories, albums, books}) => {
  strapi.services.algolia.saveObject({
    id,
    title,
    slug,
    content,
    historicalFacts,
    illustration: illustration.length > 0  ? illustration.map(({name, alternativeText, caption, url}) => ({name, alternativeText, caption, url})) : null,
    audio: audio.length > 0 ? audio.map(({name, alternativeText, caption, url}) => ({name, alternativeText, caption, url})) : null,
    categories: categories?.length || 0,
    albums: albums?.length || 0,
    books: books?.length || 0,
  }, index);
}

module.exports = {
  lifecycles: {
    afterUpdate(result, params, data) {
      if (result.published_at) {
        songToAlgolia(result);
      } else {
        strapi.services.algolia.deleteObject(result.id, index);
      }
    },
    afterDelete(result, params) {
      strapi.services.algolia.deleteObject(result.id, index);
    },
  },
};

Is it possible to do it in the new search plugin ? If no can i adapt the old plugin to work with Strapi v4 ?

@Meljesson
Copy link

I would like to know the same. My org uses algolia a lot and I have used this way of indexing our data from Strapi and it is blocking our migration to v4.

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

No branches or pull requests

2 participants