One of the productivity-boosting features of JCR is the included search engine (which is Apache Lucene in case of Jackrabbit and CRX). This feature can be used to very quickly develop an OpenSearch interface for a Sling-based application.
I have recently provided a Sling example application called Notes which I want to use to demonstrate the implementation of OpenSearch. Import the Notes application into your CRX Quickstart (download Quickstart if you do not have it, yet). For importing navigate to http://localhost:7402/crx/index.jsp and start the Package Manager.
In OpenSearch search results can be in different formats. Let's start with producing results in XHTML. Add a new file at /apps/notes/opensearch.jsp. It shall contain:
There is only a few OpenSearch-related lines like the link to the OpenSearch descriptor file (explained further below)
and the META tag that describes the result set:
The rest of this jsp is just using the standard JCR-provided query functionality to produce standard XHTML. That's it. This is your shiny new OpenSearch interface (I need to stress this once more because it's really cool: no search engine crawling or or other setup was needed. Neither was there any JCR-JSP-wiring or other web app configuration). Point your browser to: http://localhost:7402/content/notes.opensearch.html?qt=JCR to have a look (the request parameter qt denotes the query term).

The above mentioned descriptor file describes the app's search capabilities to external parties. Given the link element from above it needs to be in /apps/notes/opensearch and shall contain:
The first URL element describes the XHTML-based output implemented discussed above. OpenSearch also allows RSS-based output which is described in the second URL-element. The implementation of RSS-based OpenSearch results is even more succinct because there is less boiler-plate code. Create the renderer file /apps/notes/opensearchrss.xml.jsp and let it contain:
Hit http://localhost:7402/content/notes.opensearchrss.xml?qt=JCR with your browser or any other RSS viewer to retrieve the search results in RSS format.

OK, this is simple to implement, but what is it good for? For example, recent browsers support autodiscovery of OpenSearch engines and allow users to add them to the browser's upper right search box. Simply add a link in the HTML page's header:
I have tested this in IE7 and FF2:


Search Suggestions
There is an enhancement suggested for upcoming versions of OpenSearch that would standardize search suggestions. In Firefox, however, a similar feature is already implemented. The third URL in the descriptor file describes the interface for search suggestions in FF (i.e. this will not work in IE). The corresponding implementation at /apps/notes/opensearchsuggestions.json.jsp looks like this:
As the jsp's file name suggests the jsp returns json-formatted data. The returned data is a collection of suggestions based on the actual content (i.e. suggesting words that would produce hits). The format for a query "fi" must be of the form ["fi", ["firefox", "first", "fist"]]. Most of the code deals with String manipulation which is a bit verbose in Java. Also, I wanted to have multi-word queries like "jcr re" return suggestions for the last word only (i.e. ["jcr re", ["jcr repository", "jcr renderer"]]) which requires a couple of additional lines of code.

As usual, the full application including the complete sources is attached to this post in CRX Package Manager format.