@Override
 public boolean onQueryTextSubmit(String query) {
   if (mSearch != null) {
     mSearch.collapseActionView();
     mSearchWidget.setQuery("", false);
   }
   mController.executeSearch(query.trim());
   return true;
 }
 @Override
 public boolean onSuggestionClick(int position) {
   final Cursor c = mSearchWidget.getSuggestionsAdapter().getCursor();
   final boolean haveValidQuery = (c != null) && c.moveToPosition(position);
   if (!haveValidQuery) {
     LogUtils.d(LOG_TAG, "onSuggestionClick: Couldn't get a search query");
     // We haven't handled this query, but the default behavior will
     // leave EXTRA_ACCOUNT un-populated, leading to a crash. So claim
     // that we have handled the event.
     return true;
   }
   collapseSearch();
   // what is in the text field
   String queryText = mSearchWidget.getQuery().toString();
   // What the suggested query is
   String query = c.getString(c.getColumnIndex(SearchManager.SUGGEST_COLUMN_QUERY));
   // If the text the user typed in is a prefix of what is in the search
   // widget suggestion query, just take the search widget suggestion
   // query. Otherwise, it is a suffix and we want to remove matching
   // prefix portions.
   if (!TextUtils.isEmpty(queryText) && query.indexOf(queryText) != 0) {
     final int queryTokenIndex =
         queryText.lastIndexOf(SearchRecentSuggestionsProvider.QUERY_TOKEN_SEPARATOR);
     if (queryTokenIndex > -1) {
       queryText = queryText.substring(0, queryTokenIndex);
     }
     // Since we auto-complete on each token in a query, if the query the
     // user typed up until the last token is a substring of the
     // suggestion they click, make sure we don't double include the
     // query text. For example:
     // user types john, that matches john palo alto
     // User types john p, that matches john john palo alto
     // Remove the first john
     // Only do this if we have multiple query tokens.
     if (queryTokenIndex > -1
         && !TextUtils.isEmpty(query)
         && query.contains(queryText)
         && queryText.length() < query.length()) {
       int start = query.indexOf(queryText);
       query = query.substring(0, start) + query.substring(start + queryText.length());
     }
   }
   mController.executeSearch(query.trim());
   return true;
 }