40

GitHub has a search system, building on elastic search that has many advanced features like searching for repositories or users. Using Google, I can search GitHub for alternatives. The search syntax of GitHub however only covers negation operator.

How do I use other logic operators in GitHub's search?

Is there perhaps a feature in elastic search that can be exploited for filtering or combining Boolean queries?

3

4 Answers 4

10

GitHub's built in search covers the and, not, and or operators, as well as various other comparisons. GitHub's general guidelines on searching are located here: https://help.github.com/articles/searching-github/

With its search syntax described here: https://help.github.com/articles/search-syntax/

7
  • 1
    Yes, AND, NOT and OR work now. Thanks for your answer!
    – Bengt
    Nov 10, 2015 at 17:05
  • 55
    Nothing on those links explains how to use AND or OR, and they don't appear to work for me. Sep 22, 2017 at 22:00
  • 9
    This answer may have worked when it was first written, but it most definitely does not work now (May 2020). May 2, 2020 at 18:28
  • 3
    It works for me when doing text searches, but it's case sensitive. This returns the expected results: is:pr is:merged (JIRA-0001 OR JIRA-0002) but this does not: is:pr is:merged (JIRA-0001 or JIRA-0002) . Neither works with the qualifiers. Nov 21, 2020 at 19:53
  • 4
    It does not work for me. is:open is:pr assignee:@me and is:open is:pr review-requested:@me both work, but is:open is:pr ( assignee:@me OR review-requested:@me ) does not work. Dec 18, 2020 at 14:06
18

The default search works as though there is an implied AND operator between each search key-value pair:

is:pr is:open author:monishdeb

If you specify more than one key-value pair for a key, it uses the last one, and suppresses earlier ones in the query when results are presented.

The advanced search works as though there is an implied OR operator between each search key-value pair:

author:monishdeb author:pradpnayak repo:civicrm/civicrm-core

There is no way to combine AND and OR operators that I have found. So I don't think it is possible to find open PRs from any of several authors for a single repo.

The NOT operator can be used to exclude strings: https://help.github.com/articles/understanding-the-search-syntax/

3
  • 1
    I was able to confirm that the GraphQL API search has an implicit OR between terms, at least when I searched for multiple repositories with repo: Mar 10, 2019 at 13:51
  • Related answer I just wrote: stackoverflow.com/questions/29136057/… May 5, 2020 at 16:47
  • 1
    "The advanced search works as though there is an implied OR operator between each search key-value pair:" This isn't quite right. It acts as though there is an implied AND between each search key-valued pair, and an implied OR between duplicate usages of the same key. So, I've written this in my new answer here: webapps.stackexchange.com/a/142071/126659. May 5, 2020 at 16:56
4

The default "Pull requests" search (https://github.com/pulls) seems to have an implicit AND between all search fields, but if you duplicate a field it ignores all but the last one. So this:

is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
author:my-teammate-1 author:my-teammate-2 author:my-teammate-3

...becomes this:

is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
author:my-teammate-3

...and acts as though it were this:

is:open AND is:pr AND review-requested:ElectricRCAircraftGuy 
AND archived:false AND author:my-teammate-3

The GitHub global search (top-left bar on any page on https://github.com), however, seems to have an implicit AND between all search fields, and an implicit OR between fields you reuse, so this:

is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
author:my-teammate-1 author:my-teammate-2 author:my-teammate-3

...acts as though it were this:

is:open AND is:pr AND review-requested:ElectricRCAircraftGuy 
AND archived:false AND (author:my-teammate-1 OR 
author:my-teammate-2 OR author:my-teammate-3)

...which still does not give me the level of control I want, but is at least much more desirable behavior.

References:

  1. See also my longer answer here: https://stackoverflow.com/questions/29136057/can-i-search-github-labels-with-logical-operator-or/61618255#61618255
  2. https://github.com/isaacs/github/issues/660
0

Although it might not be specifically helpful on on logic operators AND and OR, this GitHub guide links to many extremely helpful areas, a quick scan of the list may be useful (I was trying to find how to limit my search by language, and found it in about 15 seconds).

Also, this Guide to GitHub Search Syntax does cover the NOT operator (which is a start, at least).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.