28

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?

9

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/

| improve this answer | |
  • 1
    Yes, AND, NOT and OR work now. Thanks for your answer! – Bengt Nov 10 '15 at 17:05
  • 33
    Nothing on those links explains how to use AND or OR, and they don't appear to work for me. – Christopher Sep 22 '17 at 22:00
  • 1
    This answer may have worked when it was first written, but it most definitely does not work now (May 2020). – Gabriel Staples May 2 at 18:28
16

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/

| improve this answer | |
  • 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: – Josh Dzielak Mar 10 '19 at 13:51
  • Related answer I just wrote: stackoverflow.com/questions/29136057/… – Gabriel Staples May 5 at 16:47
  • "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. – Gabriel Staples May 5 at 16:56
2

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
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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