Encapsulate your data in the SearchableEntity class

The Unified Search Service indexes the metadata that is exposed by a SearchableEntity object. The Service also returns a SearchableEntity as the content of a search result. You must prepare your application data for the Service by encapsulating it in your SearchableEntity class.

  1. Import the required classes and interfaces.
    import net.rim.device.api.unifiedsearch.SearchField;
    import net.rim.device.api.unifiedsearch.SearchFieldCriteria;
    import net.rim.device.api.unifiedsearch.SearchFieldCriteriaList;
    import net.rim.device.api.unifiedsearch.entity.SearchableEntity;
    import net.rim.device.api.unifiedsearch.searchables.Searchable;
    
  2. Retrieve an array of SearchField objects from your EntityBasedSearchable.
    SearchField[] searchfields = mySearchable.defineSupportedSearchFields();
  3. Create a SearchFieldCriteria object for each of your searchable properties. In the following code sample, the application data object myObject has a getProperty() method that returns a string for a given index. For example, if myObject described a book, then indicies 0, 1, and 2 of getProperty() could return the name, the publisher, and the number of pages in the book.
    int size = searchfields.length
    SearchFieldCriteria[] criteria = new SearchFieldCriteria[size];
    for (int i = size -1; i >= 0; --i) {
        criteria[i] = new SearchFieldCriteria(searchfields[i], new String[]{myObject.getProperty(i)});
    }
  4. Create and populate a SearchFieldCriteriaList object to hold your search field criteria.
    SearchFieldCriteriaList _sfcl = new SearchFieldCriteriaList();
    for (int i = size -1; i >= 0; --i) {
        sfcl.addCriteria(criteria[i]);
    }
  5. Implement getSearchCriteria() to return your SearchFieldCriteriaList.
    pubic SearchFieldCriteriaList getSearchCriteria() {
        return _sfcl;
    }
  6. In getData(), return your application data object. To continue with the book example, this method would return an object that represents the book.
    public Object getData() {
        return myObject;
    }
  7. In getTitle(), assign a title to this searchable entity. The title text appears in search results. To continue with the book example, myObject.getName() could return the name of a book.
    public String getTitle() {
        return myObject.getName();
    }
  8. In getSummary() provide a summary of the data in this searchable entity. The summary text appears in search results. Continuing with the book example, myObject.getDescription() could return a description of the book.
    public String getSummary() {
        return myObject.getDescription();
    }
  9. Implement getSearchable(). Retrieve the EntityBasedSearchable that your application creates to manage this object, and return it.
    public Searchable getSearchable() {
        return myPublisher.getSearchable();
    }
    
  10. Define what options should appear on the context menu when a BlackBerry device user clicks on your entity in a list of search results. For more information, see "Specify what users can do with your data in search results".
  11. If you want this SearchableEntity to display a different icon than your application icon, provide the icon in getIcon(). For more information, see "Customize the appearance of your data in search results".
After you finish:

You can specify what operations users can perform on using your SearchableEntity by implementing the getUiActions(Object, UiAction[]) method. For more information about UI actions, see Specifying what users can do with your data in search results.


Was this information helpful? Send us your comments.