directus-extension-searchsync icon indicating copy to clipboard operation
directus-extension-searchsync copied to clipboard

TimeStamp / Date

Open TorbenHammes opened this issue 1 year ago • 1 comments

Hey there, is it possible to add a float / timestamp as a UNIX Timestamp? I need it like this: https://docs.meilisearch.com/learn/advanced/working_with_dates.html#preparing-your-documents

I tried to transform a directus timestamp (string) to a UNIX timestamp before adding it to Meilisearch.

transform: (item, { flattenObject, striptags }) => {
                return {
                    ...
                    start_date: new Date(Date.parse(item.start_date)) / 1000,
                    end_date: new Date(Date.parse(item.end_date)) / 1000
                };
            },

After reindexing nothing was there anymore. My goal is to filter the date in meilisearch.

Thx a lot Torben

TorbenHammes avatar Mar 02 '23 12:03 TorbenHammes

I also had to transform an iso8601 timestamp to a numeric one for meilisearch. Using transform should be the right approach and at first glance your code should be correct. Except creating a new Date object out of the parsed timestamp is not necessary/incorrect (but technically works because JS), can be shortened to: start_date: Date.parse(item.start_date) / 1000,. Other than that, your code should work. Double check in the meilisearch dashboard if the API received a correct numerical value for start_date and end_date otherwise you likely have some other configuration issue.

The issue I ran into with date sort was that searchsync is not able to provide meilisearch any index settings. For a date field to be sortable/filterable, you must add it to the sortableAttributes and/or filterableAttributes index setting in meilisearch (using the API) like described in https://docs.meilisearch.com/learn/advanced/working_with_dates.html#filtering-by-timestamp.

To automate this, I ended up creating a fork of searchsync and implemented the index setting functionality myself (see here). I don't know if this functionality would also be useful for the other search engines, if so it could be merged into searchsync.

TeyKey1 avatar Mar 12 '23 12:03 TeyKey1