Search multiple queries in multiple repos

I have a list of repos that I searched for using the Github API. They are all repos in a specific organization and have a keyword in common in their name or description. I added the URLs of these repos to a list and now I need to use that list to refine my search even further.

The new search I need to do is for multiple keywords and search each repo in my list. But I only see searching code in the documentation. And I see the search method path:DIRECTORY looks like what I want. But I’m not sure how to insert that into an API call.

I was thinking to search with multiple queries, I can use this:

terms = 'word 1+word 2+http:\/\/someaddress.withkeyword.com+word-with-hyphen+more words'

But then how do I construct the whole thing? Can I concatenate directories too? Maybe this:

directories = 'repo address 1+repo address 2+repo address 3'

`https://api.github.com/search/code?q=terms path:directories`

I have about 130 repos to search through (and need all of their subfolders searched too), but this is the only way I can think of to fit everything into one API call. Is there a better way?

Thanks!

@andreagriffiths11 maybe you know! :slight_smile:

1 Like

Hey @wiazur – been going back through our API board to find topics that need-love and I found yours. I’m sorry it’s taken so long to address this, but I hope to help, if help is still needed :heavy_heart_exclamation:

You did link to the proper searching code documentation, which is entirely relevant to the /search endpoint:

https://docs.github.com/en/rest/reference/search

…and these docs call out what you’re looking for, here:

https://docs.github.com/en/rest/reference/search#constructing-a-search-query

…where:

A query can contain any combination of search qualifiers supported on GitHub.com. The format of the search query is:

q=SEARCH_KEYWORD_1+SEARCH_KEYWORD_N+QUALIFIER_1+QUALIFIER_N

But to answer your question:

Is there a better way?

I don’t think so! Though if you’re still working on this, months later, let us know if this is remaining, and if you’ve come up against any more hurdles in your API usage. :bow: