22

I am just looking for an example ( the correct command to fire in the advance search at github ) about searching a word inside a folder of a particular repository. I guess this will involve the "path:" option but not sure how to use it

As an example I need to search for a function name "clean" or a test case for "clean" or similar function inside the jquery test suite at the following location -
https://github.com/jquery/jquery/tree/master/test

I understand there are some filters like repo: and path: provided by github but not sure how to use them.

Also I am not satisfied with an answer posted for a similar question at - Search a github repository for the file defining a given function

I understand I can fork it to my local machine and do a search there but I don't want to download the whole repository simply to search it. I just need to search it online at the github site itself.

Thanks in advance !!

Community
  • 1
  • 1
Anmol Saraf
  • 15,075
  • 10
  • 50
  • 60
  • Note sure my answer works well with the new GitHub search engine (https://github.com/blog/1381-a-whole-new-code-search) – VonC Jan 24 '13 at 07:14

1 Answers1

24

I get 41 result with this query.

The key is to specify the user/reponame, not the the reponame:

repo:hadley/ggplot2

Combined with wildcard for the path argument, I select only one argument with this query:

repo:hadley/ggplot2 facet_wrap path:inst/*.r

So, for path, the key is to add a wildcard (which doesn't seem to be documented anywhere).
path:inst/ alone won't work. path:* or path:*.r will.


From the comments:

I need to find "beforeSend" entry which is in this file - "jquery / test / unit / ajax.js" at github.com/jquery/jquery/blob/master/test/unit/ajax.js but when I fire repo:jeresig/jquery beforeSend path:jquery/test/unit*.js in the advance search I don't get any results.
I am also confused which user should I use as jquery has many contributors like John Resig, timmywil

In this case (2012):

  • the repo is jquery/jquery (no need for a username here)
  • the path: directive to use must not repeat the repo name: so, path:test/unit*.js, not path:jquery/test/unit*.js
     repo:jquery/jquery beforeSend path:test/unit*.js

will work, and provide 4 results within JQuery Code.

Update 2022:

The query would be:

     repo:jquery/jquery beforeSend path:test extension:*js type=Code&ref=advsearch
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for answering. But I am unable to use it in my scenario of jquery at github. I tried your advice like this - Example - I need to find "beforeSend" entry which is in this file - "jquery / test / unit / ajax.js" at https://github.com/jquery/jquery/blob/master/test/unit/ajax.js but when i fire **`repo:jeresig/jquery beforeSend path:jquery/test/unit*.js`** in the advance search I don't get any results. I am also confused which **user** should I use as jquery has many contributors like John Resig, timmywil... etc etc. – Anmol Saraf Jul 31 '12 at 08:31
  • I receive only one result if I remove the "path" **repo:timmywil/jquery beforeSend** but that too is in **jquery / src / ajax.js** and not in **jquery / test / unit / ajax.js** Please suggest if I am doing something wrong. Thanks – Anmol Saraf Jul 31 '12 at 08:32
  • @AnmolSaraf don't repeat `jquery` in the `path:` directive. `path:test/unit*.js` works within a `jquery` repo. This, for instance, works: `https://github.com/search?q=beforeSend++repo%3Ajquery%2Fjquery+path%3Atest%2Funit*.js**&repo=&langOverride=&start_value=1&type=Code&language=`: that is a search with `beforeSend repo:jquery/jquery path:test/unit*.js**`. (and I don't see a `repo:jeresig/jquery`: maybe it is a private one?) – VonC Jul 31 '12 at 08:36
  • I must say this is replied lightning fast. Thanks so much for the prompt reply. I understood my mistake, actually in my case the username and reponame are the same as "jquery" only. So I had to fire it this way **`repo:jquery/jquery beforeSend path:test/*.js`** Thanks a tonne once again... You really rock :) – Anmol Saraf Jul 31 '12 at 08:46
  • @AnmolSaraf You are welcome. I have included the jquery example in the answer for other readers. – VonC Jul 31 '12 at 09:02
  • FWIW there days it doesn't work with the star for me. `path:docs/` was enough for me. – Lyubomir Jun 04 '22 at 19:01
  • @Lyubomir Indeed. I have updated the answer with a query working with the 2022 syntax. – VonC Jun 04 '22 at 21:26