mattie-strapi-bundle
mattie-strapi-bundle copied to clipboard
Custom rules on fields and Published conditions
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 ?
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.