kip2
kip2

Reputation: 6863

Android App Indexing - Autocompletion Result Handling

I have implemented deep linking as part of app indexing according to the official docs. I'm facing a few different but related problems with the search auto-completion part:

  1. Auto-completion results show only the last opened item (previously accessed items seem to be overwritten). For example, say in my app's list view of trending topics/collections the user opens item A ("shortvideos1" in the screenshot attached), resumes the feed and then opens item B ("shortvideos2"). A partial search of "shortvid" only shows the latter: "shortvideos2". Full search for "shortvideos1" yields nothing. Suggests that only the latest item shows up in the search results list.
  2. Some content accesses are missing from the results list. I have a view pager that enables the user to swipe through a list of items in a trending collection. I index the individual items by their titles, and see only some of the titles appear from the search results by those titles.

Here is how I implement the app indexing 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 Search app results

Anybody know what I'm not doing correct?

Upvotes: 0

Views: 281

Answers (1)

Stan Ct
Stan Ct

Reputation: 366

Regarding your first point, the expected behavior is that auto-complete presents all results that match or partially match your query on Google App Search, being that the results presented were viewed by the user at some point in the past. Can you please detail more on the flow of publishing your deep links using the API? Are you publishing all your content deep links when opening the App or publishing the deep link only when the content is viewed by the user?

On your second point, I must know if you opened the items of your trending collection. If not, then the reason they don't appear in the auto-completion suggestions is the same as in the previous point. The content must be opened by the user, before it can appear on the auto-completion suggestions.

Hope this helps with your doubts and let me know if you have anymore questions.

Cheers.

Upvotes: 1

Related Questions