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.globalsearch; 18 19 import android.content.ComponentName; 20 21 import java.util.ArrayList; 22 23 /** 24 * Holds information about shortcuts (results the user has clicked on before), and returns 25 * appropriate shortcuts for a given query. 26 */ 27 public interface ShortcutRepository { 28 29 static final long DAY_MILLIS = 86400000L; 30 31 /** 32 * The maximum age in milliseconds of clicks that will be used for finding 33 * and ranking shortcuts. 34 * 35 * Package visible for testing. 36 */ 37 static final long MAX_STAT_AGE_MILLIS = 7 * DAY_MILLIS; 38 39 static final long MAX_SOURCE_EVENT_AGE_MILLIS = 30 * DAY_MILLIS; 40 41 /** 42 * The mininum number of impressions to be considered for source ranking. 43 */ 44 static final int MIN_IMPRESSIONS_FOR_SOURCE_RANKING = 5; 45 46 /** 47 * The mininum number of clicks to be considered for source ranking. 48 */ 49 static final int MIN_CLICKS_FOR_SOURCE_RANKING = 3; 50 51 static final int MAX_SHORTCUTS_RETURNED = 12; 52 53 /** 54 * Checks whether there is any stored history. 55 */ hasHistory()56 boolean hasHistory(); 57 58 /** 59 * Clears all shortcut history. 60 */ clearHistory()61 void clearHistory(); 62 63 /** 64 * Deletes any database files and other resources used by the repository. 65 * This is not necessary to clear the history, and is mostly useful 66 * for unit tests. 67 */ deleteRepository()68 void deleteRepository(); 69 70 /** 71 * Closes any database connections etc held by this object. 72 */ close()73 void close(); 74 75 /** 76 * Used to Report the stats about a completed {@link SuggestionSession}. 77 * 78 * @param stats The stats. 79 */ reportStats(SessionStats stats)80 void reportStats(SessionStats stats); 81 82 /** 83 * @param query The query. 84 * @return A list short-cutted results for the query. 85 */ getShortcutsForQuery(String query)86 ArrayList<SuggestionData> getShortcutsForQuery(String query); 87 88 /** 89 * @return A ranking of suggestion sources based on clicks and impressions. 90 */ getSourceRanking()91 ArrayList<ComponentName> getSourceRanking(); 92 93 /** 94 * Refreshes a shortcut. 95 * 96 * @param source Identifies the source of the shortcut. 97 * @param shortcutId Identifies the shortcut. 98 * @param refreshed An up to date shortcut, or <code>null</code> if the shortcut should be 99 * removed. 100 */ refreshShortcut(ComponentName source, String shortcutId, SuggestionData refreshed)101 void refreshShortcut(ComponentName source, String shortcutId, SuggestionData refreshed); 102 103 } 104