Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

V4 api. Search query. Random item order when navigating result pages.

Hello,

It seems that if no sorting setting is provided in the search query the result order is random (or uses something that is often equal between repositories).

The problem is that when navigating pages using response endCursor as an `after` input, the order of results changes and following pages sometimes return elements that were already present on previous pages.

 

Order of items also appears to change if sorting criteria is equal between results e.g. same number of stars.


Once I even noticed order of items change with `sort:updated` when I am sure no changes were made to any repo. But i think that including updatedAt in to the query helped with that. At least I haven't noticed any more order changes.

 

Shortened version of my query:

query getRepos($searchQuery: String!, $startCursor: String, $count: Int!){
  search(query: $searchQuery, after: $startCursor, first: $count, type:REPOSITORY){  
    pageInfo {
      hasNextPage
      endCursor
    }
    repositoryCount
    nodes {
      ... on Repository {
        nameWithOwner
      }
    }
}
}

 

Variables i use on the first request:

{
  "searchQuery": "react-ts-table",
  "count": 2
}

 

Variables i use on the second request:

{
  "searchQuery": "react-ts-table",
"startCursor": "Y3Vyc29yOjI=", "count": 2 }

 

First response (sometimes):

{
  "data": {
    "search": {
      "pageInfo": {
        "hasNextPage": true,
        "endCursor": "Y3Vyc29yOjI="
      },
      "repositoryCount": 3,
      "nodes": [
        {
          "nameWithOwner": "agracio/ts-react-json-table"
        },
        {
          "nameWithOwner": "kolesan/react-ts-table"
        }
      ]
    }
  }
}

 

Second response expected:

{
  "data": {
    "search": {
      "pageInfo": {
        "hasNextPage": false,
        "endCursor": "Y3Vyc29yOjM="
      },
      "repositoryCount": 3,
      "nodes": [
        {
          "nameWithOwner": "tomo0613/react_table_ts"
        }
      ]
    }
  }
}

Second response actual (often):

{
  "data": {
    "search": {
      "pageInfo": {
        "hasNextPage": false,
        "endCursor": "Y3Vyc29yOjM="
      },
      "repositoryCount": 3,
      "nodes": [
        {
          "nameWithOwner": "kolesan/react-ts-table"
        }
      ]
    }
  }
}

While querying for these examples one of results was even (I have no idea how. The cursor was the same as all prevous queries, and following requests again returned the more or less expected results):

{
  "data": {
    "search": {
      "pageInfo": {
        "hasNextPage": false,
        "endCursor": null
      },
      "repositoryCount": 3,
      "nodes": []
    }
  }
}

 

Is this behaviour by design and I am missunderstanding something or is this a bug?

2 Replies
Community Manager
Message 2 of 3

Re: V4 api. Search query. Random item order when navigating result pages.

Hi @kolesan,

 

Thanks for being here! And thanks for taking the time to write this feedback. As far as I know currently, I don't believe there is a way to order API returns. Let me do some digging and see if this a feature that has been requested, I'll post any updates here.

 

Best,

Andrea

Thanks for being here, sharing, and keeping our community awesome!
Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 2
Message 3 of 3

Re: V4 api. Search query. Random item order when navigating result pages.

I am running into the same issue and am needing the search results to be ordered when searching for issues. With v3 I was able to easily page through ordered results sorted either ascending or decending, but now the search results don't seem to be in any consistent order.