Skip to content

Custom mapping with typesenseType not available for sorting #32

@Draykee

Description

@Draykee

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions