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

Add alias for fields in strapi. #55

Open
MSid01 opened this issue Jan 29, 2022 · 3 comments
Open

Add alias for fields in strapi. #55

MSid01 opened this issue Jan 29, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@MSid01
Copy link

MSid01 commented Jan 29, 2022

I want to use geosearch widget from algolia and it requires _geoloc object in the hits or record in the index. The problem is strapi does not allow to use "_geoloc" as its field name( it violates regex pattern).

@MattieBelt
Copy link
Owner

Hey @MSid01,

Thanks for your feature request, I think this could be a good addition.
Could you share an example of the config, I think an alias could work here because that doesn't make this a Algolia dependent feature. I just don't want to over complicated the config file, I'm open to suggestions.

If you want, feel free to submit an PR for this, if you need any help on setting up the workflow let me know. 👍🏼

@MattieBelt MattieBelt added the enhancement New feature or request label Feb 1, 2022
@stafyniaksacha
Copy link

Can be something like:

module.exports = ({ env }) => ({
  search: {
    enabled: env.bool('SEARCH_PLUGIN', false),
    config: {
      // ...
      contentTypes: [
        {
          name: 'api::episode.episode',
          index: 'episode',
          fields: [
            'id', 
            'title', 
            'subtitle', 
            // computed field
            {
               field: '_geoloc',
               resolve: (entity) => ({
                 lat: entity.jsonField.lat,
                 lon: entity.jsonField.lon,
              }),
            },
            // async computed field
            {
               field: '_external',
               resolve: async (entity) => {
                 // index external data
                 const data = await something(entity);

                 return data
              },
            },
          ],
        },
      ],
    },
  },
});

@MattieBelt
Copy link
Owner

@stafyniaksacha, that is a sweet config example, I really like to add computed fields and/or some sort of lifecyles. 🙏🏼
For now I'll be focusing on the admin panel development and afterwards I'll pick up some new features.

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

3 participants