Defining Custom OneBox Modules
Creating a OneBox module is a three-step process: creating a trigger, selecting a provider, and formatting the results for output.
Creating a Trigger
A OneBox module trigger determines when the OneBox provider will be invoked. When a query is executed matching the rules specified by the trigger, the trigger is invoked. A trigger can be configured as one of the following:
Selecting a Provider
- Always OnThe module will be invoked by every query
- Keyword(s)The module will be invoked by the keywords specified in the trigger definition
- Regular ExpressionThe module will be invoked when the query matches a regular expression defined by the trigger
The OneBox module provider is the entity that handles requests transmitted by the Google Search Appliance. The provider builds results based on the query and the query parameters.
There are two types of providers:
Formatting the Results
- InternalInternal providers gather information, referred to as "collections," directly from the Google Search Appliance
- ExternalExternal providers gather information from external sources, specified by a provider URL
Each provider returns results as XML. The search appliance uses XSL templates embedded in the module definition file to transform the returned XML into the final output display format.
Creating a OneBox Provider
You can implement OneBox providers using any technology that can handle HTTP Get
requests and return XML results. In Java, servlets fit these requirements. For example, the servlet shown in Listing 3
handles requests from a search appliance and returns OneBox results.
You can download the sample code
for this article and test it yourself. You deploy the servlet in Listing 3
to your application server in the same manner as any standard Java servlet. Note that you should replace the body of the findModuleResults
method to reflect your actual search results. The servlet adds each match to the array of ModuleResult
objects returned from findModuleResults
To deploy the servlet to your Google Search Appliance or appliance simulator, you must provide to the appliance or simulator a OneBox module configuration file that defines the necessary information required to find the servlet. In this case, assuming that the servlet is deployed to the URL http://localhost:8080/onebox/SampleDirectory
, the OneBox module configuration file could be as simple as the following:
<?xml version="1.0" encoding="UTF-8"?>
This OneBox module queries for sample directory information.
<!-- contents removed for the sake of brevity -->
After deploying the preceding OneBox module configuration file to your Google Search Appliance or appliance simulator, the appliance or simulator can redirect requests matching the trigger supplied in the configuration file to your OneBox provider servlet. In this case, because the trigger keywords are defined as directory|dir|phone
, any search containing a combination of these keywords would trigger a call to the OneBox provider deployed to the URL http://localhost:8080/onebox/SampleDirectory
|Figure 3. Sample Search Results: Using a simple XSL result template, here's how the results of a search from a Web browser processed by the sample OneBox module servlet might look.|
For example, the following query would trigger this provider servlet:
HTML results for the query depend on the resultTemplate
element contents defined in the OneBox module configuration file. A simple example in a Web browser might look like Figure 3
Using Google Search Appliance, a company can expose vital information using the same search technologies that Google uses to process global information on the web.
Google OneBox for Enterprise is an application programming interface (API) and framework that complements Google Search Appliance by facilitating access to real-time information in enterprise content repositories using a single search box that drives queries to provider modules.