0

根据官方文档,我已将深度链接作为应用程序索引的一部分。我在搜索自动完成部分面临一些不同但相关的问题:

  1. 自动完成结果仅显示最后打开的项目(以前访问的项目似乎被覆盖)。例如,假设在我的应用程序的趋势主题/集合列表视图中,用户打开项目 A(所附屏幕截图中的“shortvideos1”),恢复提要,然后打开项目 B(“shortvideos2”)。部分搜索“shortvid”仅显示后者:“shortvideos2”。完全搜索“shortvideos1”一无所获。建议仅在搜索结果列表中显示最新的项目。
  2. 结果列表中缺少某些内容访问。我有一个视图寻呼机,它使用户能够浏览趋势集合中的项目列表。我按标题对单个项目进行索引,并看到这些标题的搜索结果中只出现了一些标题。

以下是我实现应用索引 API 的方式:

TrendingCollectionActivity

static final Uri BASE_URI_APP = Uri.parse("android-app://" +     BuildConfig.APPLICATION_ID + "/mySchema/");
@Override
public void onCreate(Bundle savedInstance) {
// basic setup
    mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
} 
... 
public void onLoadFinished(Loader<CollectionModel> loader, CollectionModel trendingCollection) {
// adapter & view pager setup ... 
    mCollectionModel = trendingCollection
// Call the App Indexing API start method after the view has completely rendered
    startAppIndexing(mCollectionModel)    
} 

@Override
public void onStop() {
    // other teardown ...
    // register end of collection view  
    stopAppIndexing(mCollectionModel);
}

//View Pager callback to handle individual card/item swipes
@Override
public void onPageSelected(int position) {
    // get current fragment, update action bar menus, etc
    // ... 
    // app indexing: register currently visible card view
    ItemModel itemModel = mCollectionPagerAdapter.getItemModel(mViewPager.getCurrentItem());
    startAppIndexing(itemModel); // implementation very similar to the collection's onCreate()
    // register end of previous card view
    int prevIndex = mViewPager.getCurrentItem() - 1;
    ItemModel prevCard = mCollectionPagerAdapter.getItemModel(prevIndex >= 0 ? prevIndex : 1);
    stopAppIndexing(prevCard); // implementation very similar to the colleciton's onStop()
}

private void startAppIndexing(CollectionModel collectionModel) {
        mClient.connect() 

        if (trendingCollection == null) { return; }
        final String TITLE = trendingCollection.getHashtag();
        final String hostPath = new StringBuilder("collections/").append(trendingCollection.getId()).toString();
        final Uri APP_URI_COLLECTIONS = BASE_URI_APP.buildUpon().appendEncodedPath(hostPath).build(); // = android-app://net.kip2.android/myScheme/collections/7091
        Action viewAction = Action.newAction(Action.TYPE_VIEW, TITLE, APP_URI_COLLECTIONS);
        PendingResult<Status> result =  AppIndex.AppIndexApi.start(mClient, viewAction);
        result.setResultCallback(new ResultCallback<Status>() {
            @Override
            public void onResult(Status status) {
                if (status.isSuccess()) {
                    Log.d(TAG, "App Indexing API: Recorded trend "
                            + TITLE + " view successfully.");
                } else {
                    Log.e(TAG, "App Indexing API: There was an error recording the trend view."
                            + status.toString());
                }
            }
        });
}

private void stopAppIndexing(CollectionModel collectionModel) {
    if (trendingCollection == null) { return; }
        final String TITLE = trendingCollection.getHashtag();
        final String hostPath = new StringBuilder("collections/").append(trendingCollection.getId()).toString();
        final Uri APP_URI_COLLECTIONS = BASE_URI_APP.buildUpon().appendEncodedPath(hostPath).build();
        Action viewAction = Action.newAction(Action.TYPE_VIEW, TITLE, APP_URI_COLLECTIONS);
        PendingResult<Status> result =  AppIndex.AppIndexApi.end(mClient, viewAction);
        result.setResultCallback(new ResultCallback<Status>() {
           @Override
            public void onResult(Status status) {
                if (status.isSuccess()) {
                    Log.d(TAG, "App Indexing API: Recorded trend "
                           + TITLE + " view ended successfully.");
                } else {
                    Log.e(TAG, "App Indexing API: There was an error recording the trend view end."
                            + status.toString());
                }
            }
        });

        mClient.disconnect();
}

Google 搜索应用结果

有人知道我做错了什么吗?

4

1 回答 1

1

关于您的第一点,预期的行为是自动完成显示与您在 Google App Search 上的查询匹配或部分匹配的所有结果,因为用户在过去某个时间点查看了显示的结果。您能否详细说明使用 API 发布深层链接的流程?您是在打开应用程序时发布所有内容深层链接,还是仅在用户查看内容时发布深层链接?

关于你的第二点,我必须知道你是否打开了你的热门收藏品。如果不是,那么它们没有出现在自动完成建议中的原因与前一点相同。内容必须由用户打开,然后才能显示在自动完成建议中。

希望这对您的疑问有所帮助,如果您还有问题,请告诉我。

干杯。

于 2015-11-10T09:59:15.263 回答