algolia / firestore-algolia-search

Apache License 2.0
112 stars 35 forks source link

Algolia not updating Indexed Fields (proposal) #52

Closed mnogue closed 3 years ago

mnogue commented 3 years ago

I've been using this extension for a few days now and so far it's working very well. However, although creating a new Firebase document correctly indexed it in Algolia, updating the document did not.

After many hours searching for a possible cause, I noticed there were spaces between each comma, the Firebase Function gets triggered, but nothing is updated in the Algolia counter part. Since indexed fields can't contain spaces (I think?) maybe the function should remove all spaces when parsing the Indexable Fields.

config

If there's a quirk I'm missing, at least I hope this helps someone like me with OCD who needs to put a space after each comma 😁

Haroenv commented 3 years ago

Fields can contain spaces, but then the field itself would need to be name for example. It's probably a good idea to trim here anyway though:

https://github.com/algolia/firestore-algolia-search/blob/dc264bec3ba2b2f9b8b7263a96686707d42928de/functions/src/util.ts#L46

to

export const getFields = (config) =>
  (config.fields ? config.fields.split(',') : []).map((string) =>
    string.trim()
  );

or maybe even:

export const getFields = (config) =>
  config.fields ? config.fields.split(/[ ,]+/) : [];

what do you think @smomin ?

smomin commented 3 years ago

@Haroenv this makes sense. do you want to create a PR and update tests for this update?