strapi-plugin-meilisearch
strapi-plugin-meilisearch copied to clipboard
Override Services
How can i override services of this plugin?
I tried wit "strapi-server.ts" on "extensions/meilisearch/strapi-server.ts"
module.exports = (plugin) => {
plugin.services['meilisearch'].addCollectionNamePrefix = () => {
console.log('asd');
};
return plugin;
};
but seems do not work. I am doing something wrong? it this possible?
Hey @martin-landhi, I'm not aware of plugin service overriding. Can you show me the docs? Also, out of curiosity, why do you need to overwrite?
Hey @bidoubiwa
Basically i need to search by geolocation in meilisearch. But meilisearch do not allow right now use geolocation with multiple address per document. So i need to populate to meilisearch several documents and then use "districtAttribute" to get only one document as result.
For that reason i need to override the services/meilisearch/connector.js that is where the documents are sended to meilisearch in this plugin and add my custom logic there to get populated those extra documents.
My idea is add my logic inside "sanitizeEntries" function.
Are the a posibility in strapi to add my custom logic there overriding that service in strapi-server.js? That is described here:
https://docs.strapi.io/dev-docs/plugins-extension
Let me know if you need more information.
Thanks
Hey @martin-landhi could transformEntries answers your needs?
https://github.com/meilisearch/strapi-plugin-meilisearch#-transform-entries
You can also add distinctAttributes in the plugin settings here: https://github.com/meilisearch/strapi-plugin-meilisearch#-add-meilisearch-settings
My bad if it does not help. In which case I'll give it a deeper look :)
Hey @bidoubiwa
transformEntries could works but i need access to add extra entries to meilisearch from there. How can i do that?
Example:
meilisearch: {
config: {
user: {
settings: {
searchableAttributes: ['extras', 'email', 'username'],
filterableAttributes: ["_geo", "website", "extras", "type", "extras.proCategories"],
sortableAttributes: ['_geo','sortOrder'],
distinctAttribute: 'username'
},
entriesQuery: {
populate: ['projects.mainPhoto.media', 'extras.proCategories', 'website', 'profileImage'],
},
transformEntry({ entry }) {
let newEntry = {...entry};
newEntry.name = "other name"
//ADD newEntry AS EXTRA DOCUMENT HERE TO MEILISEARCH
return entry;
},
},
@bidoubiwa or any other idea to do this?
i could do it touching the project files directly on node_modules but i dont know how to rewrite them withut touch that, if i could not do it with transformEntry
Hey @martin-landhi, unfortunately, not out of the top of my head :/ Another possibility is for you to fork the project, make the changes and publish it on npm. For example: @martin-landhi/strapi-plugin-meilisearch. For example, https://www.npmjs.com/package/@mattiebelt/strapi-plugin-meilisearch