Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeStamp / Date #28

Open
TorbenHammes opened this issue Mar 2, 2023 · 1 comment
Open

TimeStamp / Date #28

TorbenHammes opened this issue Mar 2, 2023 · 1 comment

Comments

@TorbenHammes
Copy link

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

@TeyKey1
Copy link

TeyKey1 commented Mar 12, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants