gpt4 book ai didi

android - 将 SearchRecentSuggestionsProvider 与一些预定义的术语一起使用?

转载 作者:行者123 更新时间:2023-11-30 04:09:51 26 4
gpt4 key购买 nike

我正在寻找一些关于扩展 SearchRecentSuggestionsProvider 的信息,以便它可以处理两种类型的建议:

  • 用户搜索历史
  • 我希望尽可能提供预定义术语的建议

例如,当用户开始输入“Goo”时,他们可能之前搜索过“Goo Gone”——也许我还想包括“Google”,因为它在我的“特殊术语”列表中。

引用 Google 处的文档我发现我真的可以做一个或 - 使用谷歌的代码或滚动我自己的 SQLite 数据库来存储东西。有没有办法覆盖 SearchRecentSuggestionsProvider 的一部分来做我想做的事?

最佳答案

是的,您可以使用自己的类扩展 SearchRecentSuggestionsProvider。这是我为此编写的类:https://github.com/bostonbusmap/bostonbusmap/blob/master/src/boston/Bus/Map/provider/TransitContentProvider.java

package boston.Bus.Map.provider;

import boston.Bus.Map.data.RoutePool;
import boston.Bus.Map.main.Main;
import boston.Bus.Map.provider.DatabaseContentProvider.DatabaseAgent;
import boston.Bus.Map.transit.TransitSystem;
import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.SearchRecentSuggestionsProvider;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;

public class TransitContentProvider extends SearchRecentSuggestionsProvider {

private UriMatcher matcher;

public static final String AUTHORITY = "com.bostonbusmap.transitprovider";
public static final int MODE = SearchRecentSuggestionsProvider.DATABASE_MODE_QUERIES;


private static final int SUGGESTIONS_CODE = 5;

public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);

public TransitContentProvider()
{
matcher = new UriMatcher(UriMatcher.NO_MATCH);

matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SUGGESTIONS_CODE);
setupSuggestions(AUTHORITY, MODE);
}

@Override
public boolean onCreate() {
boolean create = super.onCreate();
return create;
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder)
{
int code = matcher.match(uri);
switch (code)
{
case SUGGESTIONS_CODE:
if (selectionArgs == null || selectionArgs.length == 0 || selectionArgs[0].trim().length() == 0)
{
return super.query(uri, projection, selection, selectionArgs, sortOrder);
}
else
{
ContentResolver resolver = getContext().getContentResolver();
return DatabaseAgent.getCursorForSearch(resolver, selectionArgs[0]);
}
default:
return super.query(uri, projection, selection, selectionArgs, sortOrder);
}
}
}

关于android - 将 SearchRecentSuggestionsProvider 与一些预定义的术语一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11026100/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com