Usage tips for searching code effectively in Ohloh Code

I would like to share some usage tips that have been effective in finding code I wanted in Ohloh Code (or CodeSight when looking for internal code).

Language and Extensions filter help: Its always better to filter on a specific language; that way you avoid matches on text or non-code files. In future we might support selecting the language available in the first step itself. For now, please use the language filter.

If you want to specify a language, do not type in language in the query. Use facets in the left instead. For example, instead of trying linked list in java try linked list and select Java as a language facet in the left. If you are especially looking for a class definition, you can go further ahead and use the cdef: operator and use the query term linkedlist instead (see this). For those languages, that we have not yet identified as languages, you can always go by the file extension; i.e. Use File Extensions filter (like here).

Using CamelCase: If you are sure about what you are looking for and want an exact match, it is better to use all lowercase in your query. For example; use indexwriter instead of IndexWriter. If you want more results with exact matches to be on top and less-exact matches to come later, use queries without quotes as in IndexWriter.

CamelCasing considers the individual camel-cased terms (index and writer in IndexWriter) along with the entire camel-cased word (indexwriter in IndexWriter) while matching, and it also controls how the code snippet is generated. If you are unsure of the exact terms in your camel cased query, you might want to see the individual terms highlighted in the snippet, which can also make the snippet bigger. However, if you are certain of the term (as in a class or a method name you are looking for) all lowercased query will only show the exact term in the snippets. “CameCase” inside quotes, does exact match, but will try to highlight individual camel-cased terms in the snippet, so its in the mid-ground in terms of exact match and seeing the match in highlighted code snippet. If this is what you need, put camel cased query term inside quotes as in “IndexWriter” (quotes included).

The above patterns also apply for symbols such as underscores. If you are sure you want to find map_reduce and not occurences of map and reduce, put it inside quotes as “map_reduce”.

Finding examples of API usage: If you want to find API usage examples, type in the name of the class or method (either all lowercase or camel case inside quotes), and select the proper language filter from left. You can copy such names from official API docs and try to find their usage in ohloh code. This five minute video show cases a similar use-case.

Avoid natural/verbose queries: Do not use natural language queries, such as find me an example of url encoding in c++. Think about how you’d code for such a feature, and use similar terms as you’d use in your code; for example: encode url, and use C++ filter for language (something like this).

Reformulation: Its better to try with a simple and shorter query first and refine it using facets and reformulation (i.e. trying different query terms or adding more).

Search within a project: If you intend to search inside a project, use project filtering by selecting it in the Projects facet, and in most cases, once you have a project as a filter, it is not necessary to put project name in the query. If you know the project you are interested in, it might be easier to use Ohloh’s ‘Search Code’ widget for the project. To find this you can go the project’s page in Ohloh (for example see this), and find the ‘Search Code’ widget at the bottom of the page there. Yes, this is clunky for now, but we will improve this and make it better for you in future.

I hope following the above tips will give you better results in Ohloh Code search. If you have some of your own tips, I would like to read about them. Lets share the good words among fellow developers for effective code search!

About Sushil Bajracharya

Sushil Bajracharya is a Code Search Architect at Black Duck Software.

, ,