Help Center
Local Navigation
- Integrating with BlackBerry Device Software applications
- Unified search
- Making data findable
- Define an EntityBasedSearchable class for your SearchableEntity objects
- Encapsulate your data in the SearchableEntity class
- Register your EntityBasedSearchable object with the Unified Search Service
- Notify the Unified Search Service about changes to your data
- Listening for responses from the Unified Search Service
- Removing your data from the content repository
- Using other search engines
- Ensure that a device runs a single instance of your application
- Inserting data when a device starts
- Searching
- Device interaction support
- Message list
- Custom messages
- Attachments
- Calendar
- Contact list
- Task list
- Phone
- BlackBerry Browser
- Menu items
- Find more information
- Glossary
- Provide feedback
- Document revision history
- Legal notice
BlackBerry Manuals & Help
>
Developer Documentation
>
Java Development Guides and API Reference
>
Development Guide
Integration - BlackBerry Java SDK - 6.0
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.
-
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;
-
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;
-
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]; -
Assign a meaningful name to each
SearchField.
_searchFields[0] = new SearchField("Title"); _searchFields[1] = new SearchField("Publisher"); _searchFields[2] = new SearchField("Number of pages"); } - 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."
-
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; -
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; } -
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.
-
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 } -
Use a
while loop to populate an array of searchable
entities.
Enumeration objects = myObjects.elements(); int count = 0; while (objects.hasMoreElements()) { -
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); _monitor.wait(); } } catch (InterruptedException e){ observer.error(e); return; } } -
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); } -
Notify the Unified Search Service that your are done loading
your data.
observer.completed(this, NotificationListener.TYPE_SEARCHABLE); }
-
For your
EntityBasedSearchable, determine how many data
objects currently exist in your application.
-
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; } -
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) { _monitor.notifyAll(); } } -
In
getSearchableEntities(), return the
_myEntities array that you created in step 8.
public SearchableEntity[] getSearchableEntities() { return _myEntities; }
- Customizing the appearance of your data in search results
- Specify an icon in the EntityBasedSearchable or SearchableEntity class
Previous topic: Passing queries to other search engines