FileDocCategorySizeDatePackage
Search.javaAPI DocAndroid 5.1 API4732Thu Mar 12 22:22:48 GMT 2015com.android.common

Search

public class Search extends Object
Utilities for search implementations.
see
android.app.SearchManager

Fields Summary
public static final String
SOURCE
Key for the source identifier set by the application that launched a search intent. The identifier is search-source specific string. It can be used by the search provider to keep statistics of where searches are started from. The source identifier is stored in the {@link android.app.SearchManager#APP_DATA} Bundle in {@link android.content.Intent#ACTION_SEARCH} and {@link android.content.Intent#ACTION_WEB_SEARCH} intents.
public static final String
SUGGEST_COLUMN_LAST_ACCESS_HINT
Column name for suggestions cursor. Optional. This column may be used to specify the time in {@link System#currentTimeMillis System.currentTimeMillis()} (wall time in UTC) when an item was last accessed within the results-providing application. If set, this may be used to show more-recently-used items first. See {@code SearchManager.SUGGEST_COLUMN_LAST_ACCESS_HINT} in ICS.
Constructors Summary
private Search()


       
Methods Summary
public static android.database.CursorgetSuggestions(android.content.Context context, android.app.SearchableInfo searchable, java.lang.String query)
Gets a cursor with search suggestions.

param
searchable Information about how to get the suggestions.
param
query The search text entered (so far).
return
a cursor with suggestions, or null the suggestion query failed.

        return getSuggestions(context, searchable, query, -1);
    
public static android.database.CursorgetSuggestions(android.content.Context context, android.app.SearchableInfo searchable, java.lang.String query, int limit)
Gets a cursor with search suggestions.

param
searchable Information about how to get the suggestions.
param
query The search text entered (so far).
param
limit The query limit to pass to the suggestion provider. This is advisory, the returned cursor may contain more rows. Pass {@code -1} for no limit.
return
a cursor with suggestions, or null the suggestion query failed.

        if (searchable == null) {
            return null;
        }

        String authority = searchable.getSuggestAuthority();
        if (authority == null) {
            return null;
        }

        Uri.Builder uriBuilder = new Uri.Builder()
                .scheme(ContentResolver.SCHEME_CONTENT)
                .authority(authority)
                .query("")  // TODO: Remove, workaround for a bug in Uri.writeToParcel()
                .fragment("");  // TODO: Remove, workaround for a bug in Uri.writeToParcel()

        // if content path provided, insert it now
        final String contentPath = searchable.getSuggestPath();
        if (contentPath != null) {
            uriBuilder.appendEncodedPath(contentPath);
        }

        // append standard suggestion query path
        uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);

        // get the query selection, may be null
        String selection = searchable.getSuggestSelection();
        // inject query, either as selection args or inline
        String[] selArgs = null;
        if (selection != null) {
            selArgs = new String[] { query };
        } else {                    // no selection, use REST pattern
            uriBuilder.appendPath(query);
        }

        if (limit > 0) {
            uriBuilder.appendQueryParameter(SearchManager.SUGGEST_PARAMETER_LIMIT,
                    String.valueOf(limit));
        }

        Uri uri = uriBuilder.build();

        // finally, make the query
        return context.getContentResolver().query(uri, null, selection, selArgs, null);