Incorrect pageInfo.hasNextPage with RELEVANCE sortKey in Products Query

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.

  1. Is this a known issue with the RELEVANCE sort key?
  2. Is there a workaround to get correct pagination information when using RELEVANCE sorting?
  3. Should we avoid using RELEVANCE sorting when implementing pagination?

Any insights would be greatly appreciated!

Hey Charles,

Have flagged this to our developer support team - will update here when I hear back.

Hi again Charles,

Where exactly are you using this query? Is this in the search and discovery app?

The queries are executed from a custom embedded Node.js app using the @shopify/shopify-api package through a GraphQL client.

If you test this in the GraphiQL app, are you seeing the same issue?

@Liam-Shopify Hey Liam, I know this is a bit old but I’m currently running into a similar problem.

I have a Collection > Products GraphQL query that returns a different pagination result depending on the sortKey.

  • If I use COLLECTION_DEFAULT, I get a cursor, but hasNextPage=false, and I can’t page
  • If I use TITLE, I get hasNextPage=true, and a cursor, and I can page
  • If I use RELEVANCE I just get an INTERNAL_SERVER_ERROR and I can’t do anything

This is really messing up my app. Any thoughts on why changing the sortKey would cause different pagination to be returned?

Why would I not be able to page to the next set of products when using COLLECTION_DEFAULT?

Thanks!
Kris