2

Github API allows us to search users by different parameters, and one of those parameters is location. Running the following query will give all the users living in Pakistan:

curl https://api.github.com/search/users?q=location:pakistan

Now, I would like to get all the users that either live in Pakistan or in India, but it seems that Github doesn't define a way for having an or between Pakistan & India.

I have tried the following queries, but these aren't working:

curl https://api.github.com/search/users?q=location:pakistan&location:india
curl https://api.github.com/search/users?q=location:(pakistan|india)
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76

1 Answers1

3

Your first attempt is close, but doesn't work because location isn't its own HTTP GET argument. The entire string location:pakistan is the value to the q parameter.

When you do ?q=location:pakistan&location:india you are actually submitting something like

  • q has the value location:pakistan
  • location:india is a key, but has no value

Instead, join multiple location keys with + or %20:

curl https://api.github.com/search/users?q=location:pakistan+location:india

Now the entire location:pakistan+location:india string is passed as the value to the q key.

A literal space can work too, but then you have to escape it or wrap the arguments in quotes.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • But doesn't using "+" mean AND essentially? I stringed a query together using just search terms like this `q=term1+term2+term3` and it tried to find pages that include all of those terms. But I thought the OP was asking how to use OR? Or did I misunderstand. – Azurespot Jun 25 '20 at 01:37
  • Don't infer meaning based on your preconceptions. `+` doesn't mean and _or_ or; [in a query string it means _space_](https://stackoverflow.com/a/2678602/354577). – ChrisGPT was on strike Jun 25 '20 at 02:29
  • 1
    Ah, thanks for that. Although it is treated just like AND for the purposes of how it's searching. When I use "+" it will include them all. Any idea about the "or" version of searching? – Azurespot Jun 25 '20 at 02:31
  • @Azurespot, I'm not sure what you mean. Pakistan and India are different countries, so users can't reasonably have their location set to both at the same time. And the search I show returns results (where each user is either in Pakistan _or_ in India). Are you doing a different type of search? – ChrisGPT was on strike Jun 27 '20 at 13:45
  • Oh I see, I think I was thinking of it in another way. I was just trying to figure out with any kind of search. Like say I wanted to find several keywords in a repo with many subfolders. When I tried to do use a "+" it would narrow the search to "must be all these keywords", but what I wanted was some way to say "if these repos have any of the keywords". But based on your answer, maybe I need a qualifier for my keywords? So then it would look like your example, something like `q=qualifier:term+qualifier:term+qualifier:term`. Not sure if there is a qualifier for just a keyword search though. – Azurespot Jun 28 '20 at 20:11
  • @Azurespot, yeah, that's different from this question. But it looks like [a simple `OR` works](https://github.com/search?q=ruby+OR+python&type=Repositories). Note that there's a [maximum of five `AND`s / `OR`s / `NOT`s in a single query](https://help.github.com/en/github/searching-for-information-on-github/troubleshooting-search-queries). – ChrisGPT was on strike Jun 28 '20 at 22:27
  • I see, thanks for clarifying. Yeah, I guess using an OR in this situation is about qualifiers. Funny they do have an OR that works in the GUI search, but I asked this question in the Github forums and it remained unanswered. I tried a lot of different options already. Well, thanks anyway for addressing it. – Azurespot Jun 29 '20 at 23:07