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

elasticsearch-plugin: Allow custom sort parameter input #1220

Closed
Draykee opened this issue Nov 13, 2021 · 4 comments
Closed

elasticsearch-plugin: Allow custom sort parameter input #1220

Draykee opened this issue Nov 13, 2021 · 4 comments

Comments

@Draykee
Copy link
Contributor

Draykee commented Nov 13, 2021

Is your feature request related to a problem? Please describe.
Currently we can only sort by price and name using the elasticsearch plugin.

"Current definition of sort parameter"
input SearchResultSortParameter {
    name: SortOrder
    price: SortOrder
}

Those fields are then hardcoded and parsed into the sort field of the elasticseach request body.

const sortArray = [];
    if (sort) {
        if (sort.name) {
            sortArray.push({
                'productName.keyword': { order: sort.name === SortOrder.ASC ? 'asc' : 'desc' },
            });
        }
        if (sort.price) {
            const priceField = 'price';
            sortArray.push({ [priceField]: { order: sort.price === SortOrder.ASC ? 'asc' : 'desc' } });
        }
    }

Describe the solution you'd like
I would like to have an option to push additional sort parameters to the sortArray. I guess the only way to do that is another option inside the searchConfig configuration.

mapSort?: (input: SearchInput) => string[]; // default = [ ]

The biggest problem is that we are not able to extend a graphQL input (defined in packages/core/src/api/schema/common/common-types.graphql). Maybe a search plugin needs to define those to generate them at runtime?

Describe alternatives you've considered
I'm not sure if we are able to apply sorting within the query, but if not there is no alternative.

@michaelbromley
Copy link
Member

Hi, could this not be solved with the existing ExtendSearchInputType option, combined with mapQuery?

@Draykee
Copy link
Contributor Author

Draykee commented Nov 22, 2021

No this is not possible.

  1. ExtendSearchInputType only allows primitive graphql types and not the SortOrder type.
  2. mapQuery is only used for the query property in the elasticsearch request body. I think sort parameters needs to be applied with the sort property. (But I'm not 100% sure)
  3. I think it would be nicer to have all sort parameters in the sort field of the search input type.

@michaelbromley
Copy link
Member

OK got it, thanks for clarifying. I'll review the PR later today 👍

michaelbromley pushed a commit that referenced this issue Nov 23, 2021
Closes #1220 

* feat(elasticsearch-plugin): Added custom sort parameter mapping (#1220)

* fix(elasticsearch-plugin): Removed unwanted change of price and name sort

Co-authored-by: Kevin <[email protected]>
@Draykee
Copy link
Contributor Author

Draykee commented Nov 23, 2021

Resolved with: #1230

@Draykee Draykee closed this as completed Nov 23, 2021
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