Using other search engines

The ExternalSearchProvider interface lets BlackBerry® users search data outside of the Unified Search Service. If a user receives an unsatisfactory search result, can click on other external search providers when using the Universal search feature from the Home screen. These search providers implement the ExternalSearchProvider interface.

When a user clicks a search provider, the Universal search feature invokes search() for that ExternalSearchProvider. The search provider is responsible for creating a network connection or interprocess communication connection, invoking a search on the remote server, retrieving the results, and displaying them to the user. If your application uses a remote search engine, you can consider inserting the search results in the Unified Search Service content repository to improve speed and efficiency for subsequent searches.

Some predefined external search providers include YouTube® and Google®. Third-party applications can also access external search providers. The UnifiedSearchServices.getSearchProviders() method returns a list of registered ExternalSearchProvider objects where an application can send a search.

Similar to EntityBasedSearchable objects, an ExternalSearchProvider must be registered with the Unified Search Service by using the SearchRegistry object. For more information, see "Register your EntityBasedSearchable object with the Unified Search Service".

Code sample: Implementing the ExternalSearchProvider interface


import net.rim.device.api.ui.image.Image;
import net.rim.device.api.ui.image.ImageFactory;

import net.rim.device.api.unifiedsearch.searchables.ExternalSearchProvider;
import net.rim.device.api.unifiedsearch.searchables.SearchableContentTypeConstants;


public class MySearchProvider implements ExternalSearchProvider {
    // A unique registration ID for this provider.
    private long _regId;
    
    // The external search provider icon.
    private Image _icon;
    

    // Constructor
    public MySearchProvider() {
        // Read the icon from the resource bundle
        Bitmap img = Bitmap.getBitmapResource("myicon.png");
        
        if(img != null) {
            _icon = ImageFactory.createImage(img);
        } else {
            _icon = null;
        }
    }
    
    // The provider name to be displayed.

    public String getProviderName() {
        return "Sample External Search Provider";
    }
    
    // The provider icon to be displayed.
    public Image getProviderIcon() {
        return _icon;
    }
    
    // The content type this provider offers.

    public long getContentType() {
        return SearchableContentTypeConstants.CONTENT_TYPE_MEDIA_MEMO;
    }
    
    // The search initiator will pass control to your application using this method.

    public void search(String keywords) {

        // Create network or IPC connections, send search keywords, and display the results.
    }
    
    // Allows the Unified Search Service and your application to keep track of 
    // this searchable's registration
    public long getRegistrationID()
    {
        return _regId;
    }

    public setRegistrationID(long id)
    {
        _regId = id;
    }
}

Was this information helpful? Send us your comments.