oms.servo.search
Class SearchProvider

java.lang.Object
  extended by oms.servo.search.SearchProvider

public class SearchProvider
extends java.lang.Object

Local search is a service on OPhone platform, which provides local search framework with built in application support and ISV application integration.

This class defines the constants used by search API, which can be leveraged by other application to add local search capability to itself.

Local search API consists of two parts, one is ContentProvider, which can parse given query string and return Cursor for hitting results, application using search ContentProvider need to handle the search result itself; another is Intent, which launch local search Activity with given arguments.

Search ContentProvider

Application can use search as an engine leveraging the ContentProvider. The ContentProvider provides the capability to insert, delete and update data to be indexed, as well as retrieve search result with query string.

Search content provider can be used in Android standard way, like below. Especially, the Uri and selectionArgs must be specified in query, and the syntax of selectionArgs is specified below. Further, the results need to be iterated by Cursor.respond(Bundle) method instead of cursor.getXXX(), because the latter methods only supports Sqlite based data sources.

       //URI and selectionArgs must be specified, other parameters are ignored
        Cursor cursor = getContentResolver().query(SearchProvider.CONTENT_URI, null, "Herbie Hancock", null, null);
   

Sample code snippet:

         while (cursor.next()) {
            //Use cursor.respond function to get the data.
            Bundle extras = new Bundle();
            extras = cursor.respond(extras);
            //Extract the data from search result 
            String title = extras.getString(SearchProvider.FIELD_TITLE)
            String uri = extras.getString(SearchProvider.FIELD_ID);
            String mime = extras.getString(SearchProvider.FIELD_MIME);
            //Fetch data from original database with the uri
            ...
        }
        cursor.close();
   
Usually, the FIELD_ID field stores the uri for the result. The search provider doesn't provide the full content of the results. Need to fetch data with the uri from the original database. Only FIELD_ID, FIELD_MIME and FIELD_TITLE are readable in the results, please ignore other fields of the extras bundle.

Search Intent

Application can launch local search Activity by sending Intent, as long as the following arguments are provided:

  • action - Intent.ACTION_VIEW, required
  • data - SearchProvider.CONTENT_URI, required
  • extra - (SearchProvider.EXTRA_SEARCH, queryString), optional. The search activity will be launched, and search result will be displayed against the given queryString if available.

Sample code snippet:

         Intent i=new Intent();
         i.setAction(Intent.ACTION_VIEW);
         i.setData(Uri.parse("content://search/"));
         i.putExtra("SEARCH", "Herbie Hancock");
         startActivity(i);
   

Query String Syntax

Common Query Syntax

The query string syntax is very much like Google web search's syntax, especially, the most frequently used term is as follows:
  • keyword, search given keyword in all searchable fields of all documents, like "Herbie Hancock"
  • QUERY_TYPE:typestring, search specific category, like "type:contacts"
  • QUERY_SORTBY:field, search result sorted by specific field in ascending order, like "sortby:name"
  • QUERY_SORTBY:field!, field name followed by '!' means descending order, like "sortby:name!"
  • fieldname:keyword, search given keyword in specific field, like "name:bluenote"

For example, query string "Herbie type:contacts sortby:name" means, searching my contacts list, whose information matches keyword "Herbie", and search results are sorted by contact name in ascending order.

The categories supported are defined as constants in this class as below:

  • TYPE_APPLICATION
  • TYPE_WIDGET
  • TYPE_EMAIL
  • TYPE_MESSAGE
  • TYPE_FETION
  • TYPE_SMS
  • TYPE_MMS
  • TYPE_CONTACTS
  • TYPE_CALENDAR
  • TYPE_ALL_FILE
  • TYPE_FILE
  • TYPE_AUDIO
  • TYPE_VIDEO
  • TYPE_CALL
  • TYPE_WEB

The standard field name of generic types are defined as constants in this class as below:

  • FIELD_TITLE
  • FIELD_ID
  • FIELD_MIME
  • FIELD_TIME

The currently supported field name of specific categories are defined as constants in this class as below:

  • FIELD_CONTACTS_NAME
  • FIELD_EMAIL_SENDER
  • FIELD_EMAIL_RECEIVER
  • FIELD_EMAIL_SUBJECT
  • FIELD_SMS_SENDER
  • FIELD_MMS_SENDER
  • FIELD_MMS_RECEIVER
  • FIELD_FILE_SIZE
  • FIELD_CALL_NAME
  • FIELD_CALL_DURATION
  • FIELD_CALL_TYPE

Advanced Query Syntax

A Query is a series of clauses. A clause may be prefixed by:

  • a plus QUERY_PLUS or a minus QUERY_MINUS sign, indicating that the clause is required or prohibited respectively; or
  • a term followed by a colon, indicating the field to be searched. This enables one to construct queries which search multiple fields.

A clause may be either:

  • a term, indicating all the documents that contain this term; or
  • a nested query, enclosed in parentheses. Note that this may be used with a plus/minus prefix to require any of a set of terms.

Further more:

  • The nested field indicator is illegal. You can always translate the query like "+work +author :(paulex -type:email)" to the correct form "+work +author:paulex -type:email"
  • You can use QUERY_AND QUERY_OR QUERY_NOT to indicate the nested query's relationship. Such as "China OR Chinese" or "China AND USA". Make sure Your query string is not ambiguous, such as "-baidu OR +google" or "NOT -servo", and so on.
  • The default operation is "+". So "play game" equals with "+play +game" and "play AND game".
  • The word "term" means words have the specified prefix. So "play" will hit "playing" , "player" and so on, "chin" will hit "china" and "chinese'.

Some examples:

  • "Olympics swim type:calendar" will return everything in your calendar which contains "Olympics" and "swim"
  • "Michael (music OR dance) type:(email OR sms OR mms -file) " will find the amusing things in your email, short message, multimedia message, except files. And return everything contains "Michael" and one of the two words, "music" or "dance".

See Also:
ContentProvider, Intent, Activity

Field Summary
static java.lang.String CONTENT_URI
          The Uri to access Search ContentProvider and send Intent to launch Search Activity.
static java.lang.String EXTRA_SEARCH
          This constant defines the search action when send search Intent.
static java.lang.String FIELD_CALL_DURATION
          This constant defines the duration field for TYPE_CALLOG category It's a range query, the unit is second.
static java.lang.String FIELD_CALL_NAME
          This constant defines the name field for TYPE_CALLOG category
static java.lang.String FIELD_CALL_TYPE
          This constant defines the call type field for TYPE_CALLOG category The value could be: VALUE_CALLTYPE_INCOMING VALUE_CALLTYPE_OUTGOING VALUE_CALLTYPE_MISSED
static java.lang.String FIELD_CONTACTS_NAME
          This constant defines the name field for TYPE_CONTACTS category
static java.lang.String FIELD_EMAIL_RECEIVER
          This constant defines the receiver field for TYPE_EMAIL category
static java.lang.String FIELD_EMAIL_SENDER
          This constant defines the sender field for TYPE_EMAIL category
static java.lang.String FIELD_EMAIL_SUBJECT
          This constant defines the subject field for TYPE_EMAIL category
static java.lang.String FIELD_FILE_SIZE
          This constant defines the size field for TYPE_FILE category It's a range query.
static java.lang.String FIELD_ID
          This constant defines the id field for generic searchable categories.
static java.lang.String FIELD_MIME
          This constant defines the mime field for generic searchable categories.
static java.lang.String FIELD_MMS_RECEIVER
          This constant defines the receiver field for TYPE_MMS category
static java.lang.String FIELD_MMS_SENDER
          This constant defines the sender field for TYPE_MMS category
static java.lang.String FIELD_SMS_SENDER
          This constant defines the sender field for TYPE_SMS category
static java.lang.String FIELD_TIME
          This constant defines the time field for generic searchable categories.
static java.lang.String FIELD_TITLE
          This constant defines the title field for generic searchable categories.
static java.lang.String QUERY_AND
          This constant defines the "and" of query string syntax.
static java.lang.String QUERY_MINUS
          This constant defines the "minus" of query string syntax.
static java.lang.String QUERY_NOT
          This constant defines the "not" of query string syntax.
static java.lang.String QUERY_OR
          This constant defines the "or" of query string syntax.
static java.lang.String QUERY_PLUS
          This constant defines the "plus" of query string syntax.
static java.lang.String QUERY_SORTBY
          This constant defines the "sort by" of query string syntax.
static java.lang.String QUERY_TYPE
          This constant defines the "type" of query string syntax.
static java.lang.String TYPE_ALL_FILE
          This constant defines the all file category.
static java.lang.String TYPE_APPLICATION
          This constant defines the application category.
static java.lang.String TYPE_AUDIO
          This constant defines the audio category.
static java.lang.String TYPE_CALENDAR
          This constant defines the calendar category.
static java.lang.String TYPE_CALL
          This constant defines the call category.
static java.lang.String TYPE_CONTACTS
          This constant defines the contact category.
static java.lang.String TYPE_EMAIL
          This constant defines the email category.
static java.lang.String TYPE_FETION
          This constant defines the Fetion message category.
static java.lang.String TYPE_FILE
          This constant defines the file category.
static java.lang.String TYPE_MESSAGE
          This constant defines the message category.
static java.lang.String TYPE_MMS
          This constant defines the mms category.
static java.lang.String TYPE_SMS
          This constant defines the sms category.
static java.lang.String TYPE_VIDEO
          This constant defines the video category.
static java.lang.String TYPE_WEB
          This constant defines the web category.
static java.lang.String TYPE_WIDGET
          This constant defines the widget category.
static java.lang.String VALUE_CALLTYPE_INCOMING
          This constant defines the incoming type value for FIELD_CALL_TYPE field of TYPE_CALLOG category
static java.lang.String VALUE_CALLTYPE_MISSED
          This constant defines the missed type value for FIELD_CALL_TYPE field of TYPE_CALLOG category
static java.lang.String VALUE_CALLTYPE_OUTGOING
          This constant defines the outgoing type value for FIELD_CALL_TYPE field of TYPE_CALLOG category
 
Method Summary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_URI

public static final java.lang.String CONTENT_URI
The Uri to access Search ContentProvider and send Intent to launch Search Activity.

See Also:
Constant Field Values

EXTRA_SEARCH

public static final java.lang.String EXTRA_SEARCH
This constant defines the search action when send search Intent.

See Also:
Constant Field Values

QUERY_SORTBY

public static final java.lang.String QUERY_SORTBY
This constant defines the "sort by" of query string syntax.

See Also:
Constant Field Values

QUERY_TYPE

public static final java.lang.String QUERY_TYPE
This constant defines the "type" of query string syntax.

See Also:
Constant Field Values

QUERY_PLUS

public static final java.lang.String QUERY_PLUS
This constant defines the "plus" of query string syntax.

See Also:
Constant Field Values

QUERY_MINUS

public static final java.lang.String QUERY_MINUS
This constant defines the "minus" of query string syntax.

See Also:
Constant Field Values

QUERY_AND

public static final java.lang.String QUERY_AND
This constant defines the "and" of query string syntax.

See Also:
Constant Field Values

QUERY_OR

public static final java.lang.String QUERY_OR
This constant defines the "or" of query string syntax.

See Also:
Constant Field Values

QUERY_NOT

public static final java.lang.String QUERY_NOT
This constant defines the "not" of query string syntax.

See Also:
Constant Field Values

TYPE_APPLICATION

public static final java.lang.String TYPE_APPLICATION
This constant defines the application category.

See Also:
Constant Field Values

TYPE_WIDGET

public static final java.lang.String TYPE_WIDGET
This constant defines the widget category.

See Also:
Constant Field Values

TYPE_EMAIL

public static final java.lang.String TYPE_EMAIL
This constant defines the email category.

See Also:
Constant Field Values

TYPE_MESSAGE

public static final java.lang.String TYPE_MESSAGE
This constant defines the message category. The results contain SMS, MMS and Fetion messages.

See Also:
Constant Field Values

TYPE_FETION

public static final java.lang.String TYPE_FETION
This constant defines the Fetion message category.

See Also:
Constant Field Values

TYPE_SMS

public static final java.lang.String TYPE_SMS
This constant defines the sms category.

See Also:
Constant Field Values

TYPE_MMS

public static final java.lang.String TYPE_MMS
This constant defines the mms category.

See Also:
Constant Field Values

TYPE_CONTACTS

public static final java.lang.String TYPE_CONTACTS
This constant defines the contact category.

See Also:
Constant Field Values

TYPE_CALENDAR

public static final java.lang.String TYPE_CALENDAR
This constant defines the calendar category.

See Also:
Constant Field Values

TYPE_ALL_FILE

public static final java.lang.String TYPE_ALL_FILE
This constant defines the all file category.

See Also:
Constant Field Values

TYPE_FILE

public static final java.lang.String TYPE_FILE
This constant defines the file category. Search for sdcard files, except media files If you want to search all types of files, please use TYPE_ALL_FILE

See Also:
Constant Field Values

TYPE_AUDIO

public static final java.lang.String TYPE_AUDIO
This constant defines the audio category.

See Also:
Constant Field Values

TYPE_VIDEO

public static final java.lang.String TYPE_VIDEO
This constant defines the video category.

See Also:
Constant Field Values

TYPE_CALL

public static final java.lang.String TYPE_CALL
This constant defines the call category.

See Also:
Constant Field Values

TYPE_WEB

public static final java.lang.String TYPE_WEB
This constant defines the web category.

See Also:
Constant Field Values

FIELD_TITLE

public static final java.lang.String FIELD_TITLE
This constant defines the title field for generic searchable categories.

See Also:
Constant Field Values

FIELD_ID

public static final java.lang.String FIELD_ID
This constant defines the id field for generic searchable categories.

See Also:
Constant Field Values

FIELD_MIME

public static final java.lang.String FIELD_MIME
This constant defines the mime field for generic searchable categories.

See Also:
Constant Field Values

FIELD_TIME

public static final java.lang.String FIELD_TIME
This constant defines the time field for generic searchable categories. It's a range query, the format is "yyyymmdd" Example: "time:[19860129 TO 20090517]" "time:[* TO 20080101]"

See Also:
Constant Field Values

FIELD_CONTACTS_NAME

public static final java.lang.String FIELD_CONTACTS_NAME
This constant defines the name field for TYPE_CONTACTS category

See Also:
Constant Field Values

FIELD_EMAIL_SENDER

public static final java.lang.String FIELD_EMAIL_SENDER
This constant defines the sender field for TYPE_EMAIL category

See Also:
Constant Field Values

FIELD_EMAIL_RECEIVER

public static final java.lang.String FIELD_EMAIL_RECEIVER
This constant defines the receiver field for TYPE_EMAIL category

See Also:
Constant Field Values

FIELD_EMAIL_SUBJECT

public static final java.lang.String FIELD_EMAIL_SUBJECT
This constant defines the subject field for TYPE_EMAIL category

See Also:
Constant Field Values

FIELD_SMS_SENDER

public static final java.lang.String FIELD_SMS_SENDER
This constant defines the sender field for TYPE_SMS category

See Also:
Constant Field Values

FIELD_MMS_SENDER

public static final java.lang.String FIELD_MMS_SENDER
This constant defines the sender field for TYPE_MMS category

See Also:
Constant Field Values

FIELD_MMS_RECEIVER

public static final java.lang.String FIELD_MMS_RECEIVER
This constant defines the receiver field for TYPE_MMS category

See Also:
Constant Field Values

FIELD_FILE_SIZE

public static final java.lang.String FIELD_FILE_SIZE
This constant defines the size field for TYPE_FILE category It's a range query. Example: "size:[* TO 100KB]" "size:[100KB TO 1MB]"

See Also:
Constant Field Values

FIELD_CALL_NAME

public static final java.lang.String FIELD_CALL_NAME
This constant defines the name field for TYPE_CALLOG category

See Also:
Constant Field Values

FIELD_CALL_DURATION

public static final java.lang.String FIELD_CALL_DURATION
This constant defines the duration field for TYPE_CALLOG category It's a range query, the unit is second. Example: "duration:[600 TO 1200]" "duration:[* TO 60]"

See Also:
Constant Field Values

FIELD_CALL_TYPE

public static final java.lang.String FIELD_CALL_TYPE
This constant defines the call type field for TYPE_CALLOG category The value could be:
  • VALUE_CALLTYPE_INCOMING
  • VALUE_CALLTYPE_OUTGOING
  • VALUE_CALLTYPE_MISSED

See Also:
Constant Field Values

VALUE_CALLTYPE_INCOMING

public static final java.lang.String VALUE_CALLTYPE_INCOMING
This constant defines the incoming type value for FIELD_CALL_TYPE field of TYPE_CALLOG category

See Also:
Constant Field Values

VALUE_CALLTYPE_OUTGOING

public static final java.lang.String VALUE_CALLTYPE_OUTGOING
This constant defines the outgoing type value for FIELD_CALL_TYPE field of TYPE_CALLOG category

See Also:
Constant Field Values

VALUE_CALLTYPE_MISSED

public static final java.lang.String VALUE_CALLTYPE_MISSED
This constant defines the missed type value for FIELD_CALL_TYPE field of TYPE_CALLOG category

See Also:
Constant Field Values