= extends "layout.html"
= block title
docs
= endblock
= block head
{{ assets.tag("lib/highlight.css") }}
{{ assets.tag("docs.css") }}
= endblock
= block body
bitshift is a search-engine optimized for source code: beyond supporting searches with the full range of ASCII symbols, the engine understands code, allowing users to query for metadata, like time of creation/last modification, programming language, and even symbols like function names and variables. Basic use boils down to general and advanced searches.
To perform a "general search," simply place your cursor in the search bar on our home page and begin entering text; when you stop typing for a short period of time, we'll automatically execute the query for you. As you scroll down the page, new codelets, or results, will be seamlessly downloaded from our server and appended to the end.
General searches, though, are limited. To allow users to make the best of our engine, we created an advanced search form that allows the creation of complex queries with the following specifiers:
Each of the search fields allows for numerous values; just separate them with spaces. If you'd like to search for a multi-word, space-delimited string, on the other hand, enclose it in double quotes. A query for foo bar will search for occurrences of both "foo" and "bar", while "foo bar" will search for occurrences of "foo bar".
Search groups facilitate even more robust queries: they're like a bunch of individual searches grouped into one. A user searching for occurrenes of symbol "curses" in the language "Python", and "ncurses" in "C", won't get away with: "symbols:curses ncurses" and "languages:Python C". The engine might return results "curses" in "C" and "ncurses" in "Python"! To work around that, you can use two search groups: one for "curses" in "Python", and another for "curses" in "C". bitshift will return the union of both sets of search results.
bitshift provides an API through GET requests to /search.json.
/search.json returns a JSON-encoded dictionary. If there was an error, it will contain a single key, "error", whose value will contain a human-readable description of the error. Otherwise, there will be two keys: "count", storing the number of results, and "results", storing a list of codelets. Each codelet is a dictionary with the following key–value pairs:
The following example Python 2 code searches for a given Python function definition and prints the URL of the first result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#!/usr/bin/env python
from json import loads
from sys import argv
from urllib import urlencode
from urllib2 import urlopen
def get_function(name):
params = {"q": "lang:python and func:def:%s" % name}
request = urlopen("http://bitshift.it/search.json?" + urlencode(params))
res = loads(request.read())["results"]
if res:
print "%s: %s" % (name, res[0]["url"])
else:
print "%s not found." % name
if __name__ == "__main__":
if len(argv) == 2:
get_function(argv[1])
|
bitshift is (gasp) open-source! The project is hosted on GitHub; feel free to file an issue or submit a pull request.