Define an EntityBasedSearchable class for your SearchableEntity objects

Your implementation of the EntityBasedSearchable interface manages the relationship between the Unified Search Service and the searchable entities that you create. Each EntityBasedSearchable object manages a group of SearchableEntity objects that have the same searchable properties.
  1. Import the required classes and interfaces.
    import net.rim.device.api.unifiedsearch.SearchField;
    import net.rim.device.api.unifiedsearch.searchables.EntityBasedSearchable;
    import net.rim.device.api.unifiedsearch.searchables.SearchableContentTypeConstants;
    import net.rim.device.api.unifiedsearch.searchables.Searchable;
  2. Create instance variables to store information that is relevant to your EntityBasedSearchable.
    private MySearchableEntity[] _myEntities; // You will need this in steps 8 and 11
    private long _registrationID;
    private SearchField[] _searchFields;
    private Image _icon;
    private final Object _monitor = new Object();
    private boolean _wait = false;
  3. In the constructor, create an array of SearchField objects. Each SearchField stores the name of one searchable property of your data. In the following code sample, the application data objects that are managed by this class have three searchable properties. For example, if your application data modeled books, these fields might include the title, the publisher, and number of pages.
    class MyEBS implements EntityBasedSearchable
        _searchFields = new SearchField[3];
  4. Assign a meaningful name to each SearchField.
        _searchFields[0] = new SearchField("Title");
        _searchFields[1] = new SearchField("Publisher");
        _searchFields[2] = new SearchField("Number of pages");
  5. Create an icon to appear in search results that include searchable entities managed by this EntityBasedSearchable. For more information about creating icons, see "Customizing the appearance of your data in search results."
  6. Implement getType(). Return the content type that best matches your application data. For a list of valid content types, see the net.rim.device.api.unifiedsearch.searchables.SearchableContentTypeConstants interface in the API reference.
    public long getType() {
        return SearchableContentTypeConstants.CONTENT_TYPE_MEMO;
  7. Choose the search initiators that should receive search results from your application. For more information about exposing your data to searches, see net.rim.device.api.unifiedsearch.entity.ExposureLevel class in the API reference.
    public int getPrivacyLevel() {
        return ExposureLevel.LEVEL_PUBLIC;
  8. Implement load(). If the BlackBerry® device is busy, or the battery power level is low, you may need to pause the operation of this method, and resume it when requested.
    1. For your EntityBasedSearchable, determine how many data objects currently exist in your application.
      public void load (NotificationListener observer, int loadType) {
          Vector myObjects = MyObjectManager.getDataObjects();
          if (myObjects != null) {
              int size = myObjects.size()
              if(size < 1) {
                  _myEntities = new MySearchableEntity[0]; 
              } else {
                  _myEntities = new MySearchableEntity[size];
          } else {
              // handle the condition where you have no data objects
    2. Use a while loop to populate an array of searchable entities.
          Enumeration objects = myObjects.elements();
          int count = 0;
          while (objects.hasMoreElements()) {
    3. Check whether the Unified Search Service has sent a pause command. If so, pause the operation that populates your arrray of searchable entities and notify the Service.
              if (_wait){ 
                  try {
                      synchronized(_monitor) { 
                      observer.partiallyCompleted(this, null, NotificationListener.TYPE_SEARCHABLE);
                  } catch (InterruptedException e){
    4. When your application has control of the thread again, continue to populate your array of searchable entities.
              MyObject dataObject = (MyObject) objects.nextElement();
              _myEntities[count++] = new MySearchableEntity(dataObject, this);
    5. Notify the Unified Search Service that your are done loading your data.
          observer.completed(this, NotificationListener.TYPE_SEARCHABLE);
    The Unified Search Service invokes getSearchableEntities() next to retrieve the array you populated.
  9. In pause(), change the value of the _wait variable to true. The Unified Search Service calls this method when it wants your application to stop loading data.
    public void pause() {
        _wait = true;
  10. In resume(), change the value of the _wait variable to false. Also, notify the load() method that it can resume execution. The Unified Search Service invokes resume() when it wants your application to resume loading data.
    public void resume() {
        _wait = false;
        synchronized(_monitor) {
  11. In getSearchableEntities(), return the _myEntities array that you created in step 8.
    public SearchableEntity[] getSearchableEntities() {
        return _myEntities;

Was this information helpful? Send us your comments.