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

Custom mapping with typesenseType not available for sorting #32

Open
Draykee opened this issue Mar 18, 2024 · 1 comment
Open

Custom mapping with typesenseType not available for sorting #32

Draykee opened this issue Mar 18, 2024 · 1 comment

Comments

@Draykee
Copy link

Draykee commented Mar 18, 2024

I discovered that a custom mapping defined with typesenseType like this:

updatedAt: {
    graphQlType: 'Int',
    typesenseType: 'int64', // use uint64, otherwise milliseconds wont fit
    valueFn: ({ variant }) => {
        return variant.product.updatedAt.valueOf() ?? new Date().valueOf(); 
    },
    outputFn: values => values?.[0] ?? 0,
},

Can't be used for sorting:

function sortableFields(): SortableField[] {
    return [
        {
            name: 'customMapping_updatedAt',
            alias: 'updatedAt',
        },
    ];
}

I was debugging the fields that are available while checking the schema and customMapping_updatedAt didn't appear in it.
image

If I remove the custom sorting and debug the documents getting created, I can see though that customMapping_updatedAt is used.
So I assume that The customMapping fields using typesenseType are somehow added after checking the sort schema.

My usecase: I want to sort products by "latest".

@toBeOfUse
Copy link

I couldn't get sortable fields working until I switched from the version recommended in the docs to Typesense version 0.24.0, which is the one that @michaelbromley said he uses

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