Search in sources :

Example 1 with SearchEngine

use of com.android.browser.search.SearchEngine in project coursera-android by aporter.

the class BrowserProvider method doSuggestQuery.

private Cursor doSuggestQuery(String selection, String[] selectionArgs, boolean bookmarksOnly) {
    String suggestSelection;
    String[] myArgs;
    if (selectionArgs[0] == null || selectionArgs[0].equals("")) {
        return new MySuggestionCursor(null, null, "");
    } else {
        String like = selectionArgs[0] + "%";
        if (selectionArgs[0].startsWith("http") || selectionArgs[0].startsWith("file")) {
            myArgs = new String[1];
            myArgs[0] = like;
            suggestSelection = selection;
        } else {
            SUGGEST_ARGS[0] = "http://" + like;
            SUGGEST_ARGS[1] = "http://www." + like;
            SUGGEST_ARGS[2] = "https://" + like;
            SUGGEST_ARGS[3] = "https://www." + like;
            // To match against titles.
            SUGGEST_ARGS[4] = like;
            myArgs = SUGGEST_ARGS;
            suggestSelection = SUGGEST_SELECTION;
        }
    }
    Cursor c = mOpenHelper.getReadableDatabase().query(TABLE_NAMES[URI_MATCH_BOOKMARKS], SUGGEST_PROJECTION, suggestSelection, myArgs, null, null, ORDER_BY, Integer.toString(mMaxSuggestionLongSize));
    if (bookmarksOnly || Patterns.WEB_URL.matcher(selectionArgs[0]).matches()) {
        return new MySuggestionCursor(c, null, "");
    } else {
        // get search suggestions if there is still space in the list
        if (myArgs != null && myArgs.length > 1 && c.getCount() < (MAX_SUGGEST_SHORT_SMALL - 1)) {
            SearchEngine searchEngine = mSettings.getSearchEngine();
            if (searchEngine != null && searchEngine.supportsSuggestions()) {
                Cursor sc = searchEngine.getSuggestions(getContext(), selectionArgs[0]);
                return new MySuggestionCursor(c, sc, selectionArgs[0]);
            }
        }
        return new MySuggestionCursor(c, null, selectionArgs[0]);
    }
}
Also used : SearchEngine(com.android.browser.search.SearchEngine) AbstractCursor(android.database.AbstractCursor) Cursor(android.database.Cursor)

Aggregations

AbstractCursor (android.database.AbstractCursor)1 Cursor (android.database.Cursor)1 SearchEngine (com.android.browser.search.SearchEngine)1