dimitrov-adrian / directus-extension-searchsync

Simple Directus 9 extension that sync content with remote search engine.
MIT License
116 stars 27 forks source link

Updating related field does not trigger update. #25

Open 1cgonza opened 1 year ago

1cgonza commented 1 year ago

Not so much of an issue but a question or feature request:

If I have a M2O or M2M field and update the values in those collections, the changes are not reflected on the collection I am indexing.

Following your example, a simplified config with "products" as the indexed collection with a M2O field called "category":

"collections": {
    "products": {
        "fields": ["title", "category.title"]
    }
}

If I go to the collection holding the categories and change the "title", those changes do not trigger an update on all the indexes that relate to it.

Is it possible to keep them on sync?

BTW, thanks for the extension, great job!

donni106 commented 1 year ago

i have a many to one relation location.identifier which works fine. i can change the selected value in directus edit page overlay, click on save (closing overlay for location selection) and clicking on save for the main object. it is instantly updated in my index. how is your process of updating a value?

another question according many to many relations. were you able to index them? i have tags and i am not able to index them, tried it with tags and with tags.tags_id.name but nothing lands in meilisearch documents :(

donni106 commented 1 year ago

another question according many to many relations. were you able to index them? i have tags and i am not able to index them, tried it with tags and with tags.tags_id.name but nothing lands in meilisearch documents :(

I have figured it out through reverse engineering in the extension's code :open_mouth: You need to use:

- tags.tags_id.name
- tags.0.tags_id.name
- tags.1.tags_id.name
- tags.2.tags_id.name

Unfortunately, this means hardcoding the number of expected or indexed relations. This needs to be addressed in the extension, but at least it works!

donni106 commented 7 months ago

I was able to sync tags as array with using a .searchsyncrc.cjs instead of .yml to use transform this way:

collections: {
  profiles: {
    filter: {
      ...
    },
    fields: [
      ...
      'tags.tags_id.name',
    ],
    transform: (item, { flattenObject }) => {
      return {
        ...flattenObject(item),
        tags: item.tags?.map((tag) => tag.tags_id?.name)?.filter(Boolean)
      };
    }
  }
}

=> in Meilisearch:

image