/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quicksearchbox;
import com.android.quicksearchbox.util.SQLiteTransaction;
import com.android.quicksearchbox.util.Util;
import com.google.common.annotations.VisibleForTesting;
import android.app.SearchManager;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
/**
* A shortcut repository implementation that uses a log of every click.
*
* To inspect DB:
* # sqlite3 /data/data/com.android.quicksearchbox/databases/qsb-log.db
*
* TODO: Refactor this class.
*/
public class ShortcutRepositoryImplLog implements ShortcutRepository {
private static final boolean DBG = false;
private static final String TAG = "QSB.ShortcutRepositoryImplLog";
private static final String DB_NAME = "qsb-log.db";
private static final int DB_VERSION = 30;
private static final String HAS_HISTORY_QUERY =
"SELECT " + Shortcuts.intent_key.fullName + " FROM " + Shortcuts.TABLE_NAME;
private final String mEmptyQueryShortcutQuery ;
private final String mShortcutQuery;
private static final String SHORTCUT_BY_ID_WHERE =
Shortcuts.shortcut_id.name() + "=? AND " + Shortcuts.source.name() + "=?";
private static final String SOURCE_RANKING_SQL = buildSourceRankingSql();
private final Context mContext;
private final Config mConfig;
private final Corpora mCorpora;
private final ShortcutRefresher mRefresher;
private final Handler mUiThread;
// Used to perform log write operations asynchronously
private final Executor mLogExecutor;
private final DbOpenHelper mOpenHelper;
private final String mSearchSpinner;
/**
* Create an instance to the repo.
*/
public static ShortcutRepository create(Context context, Config config,
Corpora sources, ShortcutRefresher refresher, Handler uiThread,
Executor logExecutor) {
return new ShortcutRepositoryImplLog(context, config, sources, refresher,
uiThread, logExecutor, DB_NAME);
}
/**
* @param context Used to create / open db
* @param name The name of the database to create.
*/
@VisibleForTesting
ShortcutRepositoryImplLog(Context context, Config config, Corpora corpora,
ShortcutRefresher refresher, Handler uiThread, Executor logExecutor, String name) {
mContext = context;
mConfig = config;
mCorpora = corpora;
mRefresher = refresher;
mUiThread = uiThread;
mLogExecutor = logExecutor;
mOpenHelper = new DbOpenHelper(context, name, DB_VERSION, config);
mEmptyQueryShortcutQuery = buildShortcutQuery(true);
mShortcutQuery = buildShortcutQuery(false);
mSearchSpinner = Util.getResourceUri(mContext, R.drawable.search_spinner).toString();
}
private String buildShortcutQuery(boolean emptyQuery) {
// clicklog first, since that's where restrict the result set
String tables = ClickLog.TABLE_NAME + " INNER JOIN " + Shortcuts.TABLE_NAME
+ " ON " + ClickLog.intent_key.fullName + " = " + Shortcuts.intent_key.fullName;
String[] columns = {
Shortcuts.intent_key.fullName,
Shortcuts.source.fullName,
Shortcuts.source_version_code.fullName,
Shortcuts.format.fullName + " AS " + SearchManager.SUGGEST_COLUMN_FORMAT,
Shortcuts.title + " AS " + SearchManager.SUGGEST_COLUMN_TEXT_1,
Shortcuts.description + " AS " + SearchManager.SUGGEST_COLUMN_TEXT_2,
Shortcuts.description_url + " AS " + SearchManager.SUGGEST_COLUMN_TEXT_2_URL,
Shortcuts.icon1 + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1,
Shortcuts.icon2 + " AS " + SearchManager.SUGGEST_COLUMN_ICON_2,
Shortcuts.intent_action + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
Shortcuts.intent_data + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA,
Shortcuts.intent_query + " AS " + SearchManager.SUGGEST_COLUMN_QUERY,
Shortcuts.intent_extradata + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA,
Shortcuts.shortcut_id + " AS " + SearchManager.SUGGEST_COLUMN_SHORTCUT_ID,
Shortcuts.spinner_while_refreshing + " AS " + SearchManager.SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING,
Shortcuts.log_type + " AS " + CursorBackedSuggestionCursor.SUGGEST_COLUMN_LOG_TYPE,
};
// SQL expression for the time before which no clicks should be counted.
String cutOffTime_expr = "(" + "?3" + " - " + mConfig.getMaxStatAgeMillis() + ")";
// Avoid GLOB by using >= AND <, with some manipulation (see nextString(String)).
// to figure out the upper bound (e.g. >= "abc" AND < "abd"
// This allows us to use parameter binding and still take advantage of the
// index on the query column.
String prefixRestriction =
ClickLog.query.fullName + " >= ?1 AND " + ClickLog.query.fullName + " < ?2";
// Filter out clicks that are too old
String ageRestriction = ClickLog.hit_time.fullName + " >= " + cutOffTime_expr;
String where = (emptyQuery ? "" : prefixRestriction + " AND ") + ageRestriction;
String groupBy = ClickLog.intent_key.fullName;
String having = null;
String hit_count_expr = "COUNT(" + ClickLog._id.fullName + ")";
String last_hit_time_expr = "MAX(" + ClickLog.hit_time.fullName + ")";
String scale_expr =
// time (msec) from cut-off to last hit time
"((" + last_hit_time_expr + " - " + cutOffTime_expr + ") / "
// divided by time (sec) from cut-off to now
// we use msec/sec to get 1000 as max score
+ (mConfig.getMaxStatAgeMillis() / 1000) + ")";
String ordering_expr = "(" + hit_count_expr + " * " + scale_expr + ")";
String preferLatest = "(" + last_hit_time_expr + " = (SELECT " + last_hit_time_expr +
" FROM " + ClickLog.TABLE_NAME + " WHERE " + where + "))";
String orderBy = preferLatest + " DESC, " + ordering_expr + " DESC";
return SQLiteQueryBuilder.buildQueryString(
false, tables, columns, where, groupBy, having, orderBy, null);
}
/**
* @return sql that ranks sources by total clicks, filtering out sources
* without enough clicks.
*/
private static String buildSourceRankingSql() {
final String orderingExpr = SourceStats.total_clicks.name();
final String tables = SourceStats.TABLE_NAME;
final String[] columns = SourceStats.COLUMNS;
final String where = SourceStats.total_clicks + " >= $1";
final String groupBy = null;
final String having = null;
final String orderBy = orderingExpr + " DESC";
final String limit = null;
return SQLiteQueryBuilder.buildQueryString(
false, tabl
没有合适的资源?快使用搜索试试~ 我知道了~
Android-QuickSearchBox程序源码.7z
共400个文件
class:164个
java:95个
png:74个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 115 浏览量
2022-07-06
14:32:50
上传
评论
收藏 1.68MB 7Z 举报
温馨提示
Android-QuickSearchBox程序源码.7z
资源推荐
资源详情
资源评论
收起资源包目录
Android-QuickSearchBox程序源码.7z (400个子文件)
resources.ap_ 240KB
QuickSearchBox2.apk 326KB
QuickSearchBox.class 24KB
ShortcutRepositoryImplLog.class 19KB
SearchableSource.class 15KB
SearchSettings.class 11KB
QsbApplication.class 10KB
SuggestionsProviderImpl.class 7KB
SearchableSources.class 7KB
SuggestionData.class 7KB
GoogleSuggestionProvider.class 7KB
ShortcutRepositoryImplLog$DbOpenHelper.class 7KB
SearchableCorpora.class 7KB
CursorBackedSuggestionCursor.class 7KB
WebCorpus.class 7KB
PackageIconLoader.class 6KB
SearchWidgetProvider.class 6KB
EventLogLogger.class 6KB
Suggestions.class 6KB
CorpusSelectionDialog.class 6KB
DefaultSuggestionView.class 5KB
SearchWidgetConfigActivity.class 5KB
SuggestionsAdapter.class 5KB
SuggestionsView.class 5KB
SearchableCorpusFactory.class 5KB
CorporaAdapter.class 5KB
RankAwarePromoter.class 4KB
Launcher.class 4KB
DataSuggestionCursor.class 4KB
MultiSourceCorpus.class 4KB
QueryTask.class 4KB
Util.class 4KB
Config.class 4KB
GoogleSearch.class 4KB
SourceShortcutRefresher.class 4KB
AppsCorpus.class 3KB
SingleSourceCorpus.class 3KB
ShortcutRepositoryImplLog$SuggestionCursorImpl.class 3KB
ListSuggestionCursor.class 3KB
SuggestionViewInflater.class 3KB
SuggestionsProviderImpl$SuggestionCursorReceiver.class 3KB
ShortcutCursor.class 3KB
SingleThreadNamedTaskExecutor.class 3KB
MultiSourceCorpus$Result.class 3KB
DelayingSuggestionsAdapter.class 3KB
SingleThreadNamedTaskExecutor$Worker.class 3KB
ShortcutRepositoryImplLog$Shortcuts.class 2KB
R$drawable.class 2KB
GoogleSuggestionProvider$SuggestionsCursor.class 2KB
BatchingNamedTaskExecutor.class 2KB
SearchActivityView.class 2KB
ShouldQueryStrategy.class 2KB
AbstractSuggestionCursorWrapper.class 2KB
CachingIconLoader.class 2KB
PerNameExecutor.class 2KB
WebCorpus$WebResult.class 2KB
AbstractCorpusRanker.class 2KB
CorpusViewInflater.class 2KB
ShortcutRepositoryImplLog$ClickLog.class 2KB
DefaultCorpusRanker$CorpusComparator.class 2KB
BarrierConsumer.class 2KB
SourceShortcutRefresher$ShortcutRefreshTask.class 2KB
GoogleSettings.class 2KB
ShortcutRepositoryImplLog$SourceStats.class 2KB
DefaultCorpusRanker.class 2KB
R$string.class 2KB
RoundRobinPromoter.class 2KB
ShortcutPromoter.class 2KB
SuggestionsFooter.class 2KB
SuggestionsView$ItemLongClickListener.class 2KB
ChoiceActivity.class 2KB
QuickSearchBox$SearchTextWatcher.class 2KB
ShortcutRepositoryImplLog$3.class 2KB
SuggestionsView$ItemClickListener.class 2KB
SuggestionsView$ItemSelectedListener.class 2KB
SuggestionCursorWrapper.class 2KB
NamingThreadFactory.class 2KB
SearchWidgetConfigActivity$SourceClickListener.class 2KB
CorpusSelectionDialog$CorpusClickListener.class 2KB
SearchableSource$CursorBackedSourceResult.class 2KB
QuickSearchBox$SelectionHandler.class 2KB
ContactSuggestionView.class 2KB
QuickSearchBox$CorpusSelectionListener.class 2KB
ShortcutRepositoryImplLog$4.class 2KB
SearchableSources$2.class 1KB
QuickSearchBox$SuggestionsViewKeyListener.class 1KB
Source.class 1KB
SingleSourceCorpusResult.class 1KB
ShortcutRepositoryImplLog$3$1.class 1KB
ShortcutRepositoryImplLog$1.class 1KB
R$id.class 1KB
SuggestionPosition.class 1KB
CorpusView.class 1KB
SearchSettings$1.class 1KB
ListSuggestionCursorNoDuplicates.class 1KB
ShortcutRepositoryImplLog$5.class 1KB
QsbApplication$1.class 1KB
AbstractSuggestionCursor.class 1KB
QuickSearchBox$QueryTextViewKeyListener.class 1KB
QuickSearchBox$ButtonsKeyListener.class 1KB
共 400 条
- 1
- 2
- 3
- 4
资源评论
BryanDing
- 粉丝: 297
- 资源: 5587
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功