41

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 the negation operator.

How do I use boolean operators in GitHub's search?

Is there perhaps a feature in elastic search that can be exploited to enable boolean queries?

0

4 Answers 4

12

Code Search

GitHub's code search* supports boolean expressions:

  • You can use the operators AND, OR, and NOT to combine search terms.
  • By default, adjacent terms separated by whitespace are equivalent to using the AND operator.
  • You can use parentheses to express more complicated boolean expressions.
Additional Resources:

GitHub Search Documentation
   >  Understanding Code Search Syntax*
             #  Using boolean operations
             #  Using qualifiers
             #  Using regular expressions


 


* Applies only to GitHub code search. Syntax and qualifiers for searching for non-code content, such as issues, users, and discussions, is not the same as the syntax for code search. For more information on non-code search, see "About searching on GitHub" and "Searching on GitHub."

0
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/

2
5

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: Stack Overflow: Can I search github labels with logical operator OR?
  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 you have read our privacy policy.

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