skratchdot / github-code-search.user.js

A user script that adds a search box to repository pages which allows you to search the code in that repository.
54 stars 4 forks source link

Search for code with quotation marks #7

Closed muescha closed 11 years ago

muescha commented 11 years ago

just send a bug report to github but then i find this :-)

it would be nice if it is implemented


i like to search for this codesnippet in code:

a) unchanged codesnippet

$:.unshift("/Library/RubyMotion/lib")

no result

b) without quotation marks

$:.unshift( /Library/RubyMotion/lib )

no result

c) removed inline quotation marks add outline quotation marks

"$:.unshift( /Library/RubyMotion/lib )"

results

it should find it with version a) ( + additional bonus: find it with ' and with " )

or if it is tooo much magic:

add a info to the no results message how to find codesnippets with quotation marks (and maybe also create the new search string this way for me to search for it with one click)

skratchdot commented 11 years ago

There's nothing I can do to change the way Github search works (all this script does is make ajax requests to the normal search page), but I can display a message about quotes.

For this to work, I was able to escape quotes using a backslash.

With quotes:

https://github.com/search?type=Code&q=%24%3A.unshift(%22%2FLibrary%2FRubyMotion%2Flib%22)+repo%3Atransist%2Fmotion_spinner&p=1

Escaping quotes with backslash:

https://github.com/search?type=Code&q=%24%3A.unshift(%5C%22%2FLibrary%2FRubyMotion%2Flib%5C%22)+repo%3Atransist%2Fmotion_spinner&p=1

Also, for future reference, there are going to be certain keywords that probably make this search break. Click on the "cheatsheet"/"prefixes" from the search page: https://github.com/search

I'll try to fix this by adding info to the no results page (like you suggested). I like the idea of finding both version a and version b, but I want to get away from doing too much behind the scenes. I'd like to keep it working the way regular github search does, because if I start adding too much additional logic, I might start introducing bugs :)

muescha commented 11 years ago

thanks it works :-)

i agree with you that too much magic is not good.

very good idea to escape the quotes! :+1:

but maybe its better to make a new script from this snipped to get it also into the the normal search result started from the original search textfield (and results in this screen: https://github.com/search?type=Code&q=%24%3A.unshift(%22%2FLibrary%2FRubyMotion%2Flib%22)+repo%3Atransist%2Fmotion_spinner&p=1 )

skratchdot commented 11 years ago

I think that makes sense. Would you object to me just adding that functionality into this script? The more scripts I add, the more of a pain it is to maintain.

Also, I'd either have to add duplicate code in this script, or people that already have this installed would be missing out on functionality...

muescha commented 11 years ago

Mhh. Better only in one script.

I think this is fixed in the future because a github staff answered me that they are improving the codesearch in future

muescha commented 11 years ago

FYI: they fixed the code search :-) for this search with quotes

skratchdot commented 11 years ago

Ahh. That's good news!

Thanks for checking out this script and making it better.

Take care.