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

QueryAll with sort order other than by id returns duplicate and incomplete search results. #341

Open
tomwscott opened this issue Jul 12, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@tomwscott
Copy link

I'm not sure if this is an issue or a feature request but if the query passed to QueryUtils applies a sort order other than by id the search results after the first page will be incomplete and likely include duplicate results.

Whilst it is hinted at in the code documentation, there is nothing that explicitly prevents a sort order being added as part of the query which then breaks the assumption here:

return baseQuery.addWhere("id > :lastId", "lastId", lastElementId).execute();

For my use case it would be great to be able fetch all results ordered by key.

If the only supported mechanism in the library for querying all entities is when ordered by id it would be great to have that as part of the function name to make it explicit.

@jenschude
Copy link
Contributor

The QueryAll is a helper class to conveniently get all elements of a query without the limitations from using offset & limit query parameters. As a matter of fact it has limitations itself which means that the result must be sorted by ID too else the algorithm it not working correctly as described here: https://docs.commercetools.com/api/general-concepts#iterating-over-all-elements

If you already sort by key you may have to add an additional sort by ID in your request cause the sort by ID would not be added as can be seen here:

return !withLimit.getQueryParam("sort").isEmpty() ? withLimit : withLimit.withSort("id asc");

So to have a different option for paging the result is a feature request and I don't know if or when we could work on it.

Besides you are still free to use the implementation as a starting point to adjust it to your needs.

@jenschude jenschude added the enhancement New feature or request label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants