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

Override Services #772

Open
martin-landhi opened this issue Jul 17, 2023 · 6 comments
Open

Override Services #772

martin-landhi opened this issue Jul 17, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@martin-landhi
Copy link

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?

@bidoubiwa
Copy link
Contributor

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?

@bidoubiwa bidoubiwa added the needs more info This issue needs a minimal complete and verifiable example label Jul 18, 2023
@martin-landhi
Copy link
Author

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

@bidoubiwa
Copy link
Contributor

bidoubiwa commented Jul 18, 2023

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 :)

@martin-landhi
Copy link
Author

martin-landhi commented Jul 18, 2023

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;
            },
          },

@martin-landhi
Copy link
Author

@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

@bidoubiwa
Copy link
Contributor

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

@bidoubiwa bidoubiwa added enhancement New feature or request and removed needs more info This issue needs a minimal complete and verifiable example labels Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants