public void buildCorpusGroups() { Suggestions suggestions = getSuggestions(); SuggestionCursor promoted = getCurrentPromotedSuggestions(); HashSet<String> promotedSuggestions = new HashSet<String>(); if (promoted != null && promoted.getCount() > 0) { promoted.moveTo(0); do { promotedSuggestions.add(SuggestionUtils.getSuggestionKey(promoted)); } while (promoted.moveToNext()); } if (suggestions == null) { mCorpusGroups = null; } else { if (mCorpusGroups == null) { mCorpusGroups = new ArrayList<SuggestionCursor>(); } else { mCorpusGroups.clear(); } for (CorpusResult result : suggestions.getCorpusResults()) { ListSuggestionCursor corpusSuggestions = new ListSuggestionCursor(result.getUserQuery()); for (int i = 0; i < result.getCount(); ++i) { result.moveTo(i); if (!result.isWebSearchSuggestion()) { if (!promotedSuggestions.contains(SuggestionUtils.getSuggestionKey(result))) { corpusSuggestions.add(new SuggestionPosition(result, i)); } } } if (corpusSuggestions.getCount() > 0) { mCorpusGroups.add(corpusSuggestions); } corpusSuggestions.close(); } } }