dimitrov-adrian / directus-extension-searchsync

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

Directus relationships don't seem to be working #17

Closed sGerli closed 2 years ago

sGerli commented 2 years ago

When trying to index a collection with a relationship field like thumbnail.filename_disk it doesn't index that field.

I've only seen the id working, if you add thumbnail as the field it will index just the id. But sometimes you need other data, like in the case of the author of a post you might want to index the name, but author.name won't work.

Tested using Directus v9.10.0

kamil-malinski commented 2 years ago

same here

hope it gets fixed

kamil-malinski commented 2 years ago

I just created a pull request to fix the issue: https://github.com/dimitrov-adrian/directus-extension-searchsync/pull/18

narduin commented 2 years ago

Hello, could you post a working example of this behaviour please? I can't seem to make it work on a many to many relationship.

My schema looks like this and I want to include collection.categories.category.title to the search index.

collection {
    date_created
    title
    categories {
        category {
            title
            description
        }
    }
}

Thanks a lot!

TorbenHammes commented 2 years ago

I also need an example for this. @narduin @dimitrov-adrian @sGerli Thx a lot :-D

narduin commented 2 years ago

Hi @TorbenHammes, I was able to make something kinda work with the following conf. I had to switch from a .json to a .js conf file.

// .searchsyncrc.js

const config = {
    server: {...},
    collections: {
        missions: {
            collectionField: "_collection",
            filter: {
                status: "published",
            },
            fields: ["title", "slug", "content", "categories.category.title"],
            transform: (item, { flattenObject, striptags }) => {
                return {
                    ...flattenObject(item),
                    content: striptags(item.content),
                    category: item.categories[0].category.title,
                };
            },
        },
    },
};

// Use as object.
module.exports = config;

This conf indexes correctly title, slug, content and category but it also creates an empty categories.0.category.title. I guess I'm doing something wrong but I don't know what :)

kamil-malinski commented 2 years ago

@narduin

const config = {
  server: {
    ...
  },
  collections: {
    collection: {
      filter: {
          ...
      },
      fields: [
        "categories.category.title"
      ],
    },
  },
};

module.exports = config;
TorbenHammes commented 2 years ago

Thank you πŸ™πŸΌπŸ™πŸΌπŸ™πŸΌ

jorauch commented 1 year ago

Hi, I have a similar problem with a meilisearch and no related date is written in the index, e.g. 'category.title'. Fixes the #18 only easticsearch?

Thanks for any help.

Tested using Directus 9.21 and Meilisearch 0.30