Meilisearch with GeoSearch

Hi everyone,

I am looking for a data structure data attends the geo search from MeiliSearch. Does someone have any examples?

Thanks!

I found a way to solve it. The plugin enables us to transform data before to send to Meilisearch: GitHub - meilisearch/strapi-plugin-meilisearch: A strapi plugin to add your collections to meilisearch

The date fields have to be UNIX timestamps: Working with dates | Meilisearch Documentation v0.29

at config/plugins.js


meilisearch: {
    config: {
      // Your meili host
      host: env("MEILISEARCH_HOST"),
      // Your master key or private key
      apiKey: env("MEILISEARCH_API_KEY_MASTER"),
      attraction: {
        transformEntry({ entry }) {
          return {
            id: entry.id,
            name: entry.name,
            slug: entry.slug,
            description: entry.description,
            createdAt: dateToTimeStamp(entry.createdAt),
            updatedAt: dateToTimeStamp(entry.updatedAt),
            publishedAt: dateToTimeStamp(entry.publishedAt),
            _geo: transformGeo(entry.latitude, entry.longitude),
          };
        },
        settings: {
          filterableAttributes: ["_geo"],
        },
      },
    },
  },
});

const dateToTimeStamp = (date) => {
  const dateInstance = new Date(date);
  return dateInstance.getTime();
};

const transformGeo = (latitude, longitude) => {
  return {
    lat: latitude,
    lng: longitude,
  };
};

After resending your data in the correct format, you have to add a new filterable attribute, or also you can add this config on the plugin as in the example above: