1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.quicksearchbox; 18 19 import com.android.quicksearchbox.util.Consumer; 20 21 import java.util.Collection; 22 import java.util.Map; 23 24 /** 25 * Holds information about shortcuts (results the user has clicked on before), and returns 26 * appropriate shortcuts for a given query. 27 */ 28 public interface ShortcutRepository { 29 30 /** 31 * Checks whether there is any stored history. 32 * 33 * @param consumer Consumer that the result will be passed to. 34 * The value passed to the consumer will always be non-null. 35 * The consumer will be called on an unspecified thread, and will always 36 * get called eventually. 37 */ hasHistory(Consumer<Boolean> consumer)38 void hasHistory(Consumer<Boolean> consumer); 39 40 /** 41 * Removes a single suggestion from the stored history. 42 */ removeFromHistory(SuggestionCursor suggestions, int position)43 void removeFromHistory(SuggestionCursor suggestions, int position); 44 45 /** 46 * Clears all shortcut history. 47 */ clearHistory()48 void clearHistory(); 49 50 /** 51 * Closes any database connections etc held by this object. 52 */ close()53 void close(); 54 55 /** 56 * Reports a click on a suggestion. 57 * Must be called on the UI thread. 58 */ reportClick(SuggestionCursor suggestions, int position)59 void reportClick(SuggestionCursor suggestions, int position); 60 61 /** 62 * Gets shortcuts for a query. 63 * 64 * @param query The query. May be empty. 65 * @param allowedCorpora The corpora to get shortcuts for. 66 * @param allowWebSearchShortcuts Whether to include web search shortcuts. 67 * @param consumer Consumer that the shortcuts cursor will be passed to. 68 * The shortcut cursor passed to the consumer may be null if there are no shortcuts. 69 * If non-null, and the consumer returns {@code true}, the consumer must ensure that 70 * the shortcut cursor will get closed eventually. 71 * The consumer will be called on an unspecified thread, and will always 72 * get called eventually. 73 */ getShortcutsForQuery(String query, Collection<Corpus> allowedCorpora, boolean allowWebSearchShortcuts, Consumer<ShortcutCursor> consumer)74 void getShortcutsForQuery(String query, Collection<Corpus> allowedCorpora, 75 boolean allowWebSearchShortcuts, 76 Consumer<ShortcutCursor> consumer); 77 78 /** 79 * Updates a shortcut in the repository after it's been refreshed. 80 * 81 * @param source The source of the shortcut that's been refreshed 82 * @param shortcutId The ID of the shortcut that's been refershed 83 * @param refreshed The refreshed shortcut suggestion. 84 */ updateShortcut(Source source, String shortcutId, SuggestionCursor refreshed)85 void updateShortcut(Source source, String shortcutId, SuggestionCursor refreshed); 86 87 /** 88 * Gets scores for all corpora in the click log. 89 * 90 * @param consumer Consumer that the result will be passed to. 91 * The result is a map of corpus name to score. A higher score means that the corpus 92 * is more important. 93 * The value passed to the consumer may be non-null. 94 * The consumer will be called on an unspecified thread, and will always 95 * get called eventually. 96 */ getCorpusScores(Consumer<Map<String,Integer>> consumer)97 void getCorpusScores(Consumer<Map<String,Integer>> consumer); 98 } 99