When querying products with sortKey: RELEVANCE
, the pageInfo.hasNextPage
is incorrectly returning false
even when there are more results available. However, when using other sort keys (like TITLE
), pagination works as expected.
Example
Here are two identical queries, only differing in their sortKey
:
With sortKey: RELEVANCE
:
graphql
query {
products(first: 10, reverse: true,
query: "(title:'Marshall Plan' OR title:'Marshall' OR title:'Plan') AND OR (sku:'Marshall Plan')",
sortKey: RELEVANCE
) {
edges { ... }
pageInfo {
hasNextPage
hasPreviousPage
endCursor
startCursor
}
}
productsCount(query: "(title:'Marshall Plan' OR title:'Marshall' OR title:'Plan') AND OR (sku:'Marshall Plan')") {
count
}
}
Response:
json
{
"pageInfo": {
"hasNextPage": false,
"hasPreviousPage": false
},
"productsCount": {
"count": 38
}
}
Response with sortKey: TITLE instead of RELEVANCE:
json
{
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": false
},
"productsCount": {
"count": 38
}
}
Since we’re requesting 10 items (first: 10
) and there are 38 total results, hasNextPage
should be true
regardless of the sortKey
used.
- Is this a known issue with the
RELEVANCE
sort key? - Is there a workaround to get correct pagination information when using
RELEVANCE
sorting? - Should we avoid using
RELEVANCE
sorting when implementing pagination?
Any insights would be greatly appreciated!