Scripted Searches for Java Code in Popular Source Code Search Engines

 Posted on 
 ·  6 minutes reading time

Sometimes the best way to solve a programming problem is to see how others have done the same thing. When that happens, having immediate access to the various search engines helps get you back on track quickly. Here are OpenSearch plug-ins (suitable for Firefox and MSIE7) that will search the Java code in five of the more popular source code search engines.

Krugle

Krugle is not only a source code search engine, but an entire environment for developers to review an comment on code. It supports code search by crawling, parsing and indexing code found in all open source repositories, as well as code that exists in archives, mailing lists, blogs, and web pages. Krugle also provides answers to code-related technical questions: related code, dependencies, licensing information, compatibility requirements, bug reports and news group postings. Finally, it lets one add comments to entire code files or specific lines of code, allowing for useful code-centric communication between developers.

Install Krugle Java Code Search for Firefox and MSIE7. Plug-in source:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!-- Generated by searchplugins.net search plugin generator -->
<!-- http://www.searchplugins.net/generate.aspx -->
<!-- Plugin list available at http://www.searchplugins.net/pluginlist.aspx -->
<opensearchdescription>
  <shortname>Krugle Java Code Search</shortname>
  <description>Search Krugle Java Code Search</description>
  <tags>krugle java programming code</tags>
  <image height="16" width="16" type="image/x-icon">http://www.krugle.com/favicon.ico</image>
  <url type="text/html" method="GET" template="http://www.krugle.com/kse/files?query={searchTerms}&lang=java">
  <inputencoding>UTF-8</inputencoding>
  <adultcontent>false</adultcontent>
</url></opensearchdescription>

Koders

Koders is a repository of open source project code. From their own description of themselves:

Koders.com is the leading search engine for open source code. Our source code optimized search engine provides developers with an easy-to-use interface to search for source code examples and discover new open source projects which can be leveraged in their applications.

Note also that you can get a plugin for Eclipse to perform the searches right from the IDE. Install Koders Java Search in Firefox or MSIE7. Plug-in source:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!-- Generated by searchplugins.net search plugin generator -->
<!-- http://www.searchplugins.net/generate.aspx -->
<!-- Plugin list available at http://www.searchplugins.net/pluginlist.aspx -->
<opensearchdescription>
  <shortname>Koders "Java" Search</shortname>
  <description>Search Koders for Java code</description>
  <tags>koders programming java</tags>
  <image height="16" width="16" type="image/x-icon">http://www.koders.com/favicon.ico</image>
  <url type="text/html" method="GET" template="http://www.koders.com/default.aspx?s={searchTerms}&btn=Search&la=Java&li=*">
  <inputencoding>UTF-8</inputencoding>
  <adultcontent>false</adultcontent>
</url></opensearchdescription>

Codefetch

Codefetch is a search engine for source code from published books. Oftentimes, publishers and/or authors will make the example source code available online. Codefetch indexes those bits of sample source code and provides links to bookstores where you can buy the book associated with the code. Be sure to check out their help and examples screen for the more sophisticated search and limiting parameters.

Install Codefetch Java Search in Firefox or MSIE7. Plug-in source:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!-- Generated by searchplugins.net search plugin generator -->
<!-- http://www.searchplugins.net/generate.aspx -->
<!-- Plugin list available at http://www.searchplugins.net/pluginlist.aspx -->
<opensearchdescription>
  <shortname>Search Codefetch for Java Code</shortname>
  <description>Search Search Codefetch for Java Code</description>
  <tags>codefetch programming java</tags>
  <image height="16" width="16" type="image/x-icon">http://www.codefetch.com/favicon.ico</image>
  <url type="text/html" method="GET" template="http://www.codefetch.com/search?qy={searchTerms}&lang=java">
  <inputencoding>UTF-8</inputencoding>
  <adultcontent>false</adultcontent>
</url></opensearchdescription>

O'Reilly Publishing

Another source of edited example code is from O'Reilly Publishing. This, too, is "in the labs" so it may go away at some point. In the meantime, one can "find relevant sample code from nearly 700 O'Reilly books. The database currently contains over 123,000 individual examples, composed of 2.6 million lines of code — all edited and ready to use." Do make note of the O'Reilly Policy on Re-Use of Code Examples from Books.

Install O'Reilly Java Code Search in Firefox and MSIE7. Plug-in source:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!-- Generated by searchplugins.net search plugin generator -->
<!-- http://www.searchplugins.net/generate.aspx -->
<!-- Plugin list available at http://www.searchplugins.net/pluginlist.aspx -->
<opensearchdescription>
  <shortname>O'Reilly Java Code Search</shortname>
  <description>Search O'Reilly Java Code Search</description>
  <tags>o'reilly java programming code</tags>
  <image height="16" width="16" type="image/x-icon">http://labs.oreilly.com/favicon.ico</image>
  <url type="text/html" method="GET" template="http://labs.oreilly.com/search.xqy?t=code&q={searchTerms}+cat%3Ajava">
  <inputencoding>UTF-8</inputencoding>
  <adultcontent>false</adultcontent>
</url></opensearchdescription>

Google Code Search

In the nebulous Google Labs (will it disappear? will it stay in the labs? will it become a "normal" service?) there is a Code Search service. This is how Google describes it:

Google Code Search helps you find function definitions and sample code by giving you one place to search publicly accessible source code hosted on the Internet. With Google Code Search, you can:

  • Use regular expressions to search more precisely
  • Restrict your search by language, license or filename
  • View the source file with links back to the entire package and the webpage where it came from

The use of regular expressions seems to give Google an edge over the others, although I don't think the Google service is as comprehensive in coverage as Koders.

Install Google Code Search for Java into Firefox or MSIE7. Plug-in source:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!-- Generated by searchplugins.net search plugin generator -->
<!-- http://www.searchplugins.net/generate.aspx -->
<!-- Plugin list available at http://www.searchplugins.net/pluginlist.aspx -->
<opensearchdescription>
  <shortname>Google Code Search for Java</shortname>
  <description>Search Google Code Search for Java</description>
  <tags>googlecodesearch java programming google</tags>
  <image height="16" width="16" type="image/x-icon">http://www.google.com/favicon.ico</image>
  <url type="text/html" method="GET" template="http://www.google.com/codesearch?as_q={searchTerms}&btnG=Search+Code&hl=en&as_lang=java&as_license_restrict=i&as_license=&as_package=&as_filename=&as_case=">
  <inputencoding>UTF-8</inputencoding>
  <adultcontent>false</adultcontent>
</url></opensearchdescription>