SuggestionsPortletDisplayBuilder { protected void buildRelatedQueriesSuggestions( SuggestionsPortletDisplayContext suggestionsPortletDisplayContext) { if (!_relatedQueriesSuggestionsEnabled) { return; } suggestionsPortletDisplayContext.setRelatedQueriesSuggestionsEnabled( true); List<SuggestionDisplayContext> relatedQueriesSuggestions = _buildRelatedQueriesSuggestions(); suggestionsPortletDisplayContext.setHasRelatedQueriesSuggestions( !relatedQueriesSuggestions.isEmpty()); suggestionsPortletDisplayContext.setRelatedQueriesSuggestions( relatedQueriesSuggestions); } SuggestionsPortletDisplayBuilder(Html html, Http http); SuggestionsPortletDisplayContext build(); void setKeywords(String keywords); void setKeywordsParameterName(String keywordsParameterName); void setRelatedQueriesSuggestions(
		List<String> relatedQueriesSuggestions); void setRelatedQueriesSuggestionsEnabled(
		boolean relatedQueriesSuggestionsEnabled); void setSearchURL(String searchURL); void setSpellCheckSuggestion(String spellCheckSuggestion); void setSpellCheckSuggestionEnabled(
		boolean spellCheckSuggestionEnabled);  }
@Test public void testGetRelatedQueriesSuggestions() { List<SuggestionDisplayContext> suggestionDisplayContexts = buildRelatedQueriesSuggestions(Arrays.asList("alpha")); assertSuggestion( "[alpha] | q=X(q<<alpha)", suggestionDisplayContexts.get(0)); }
@Test public void testGetRelatedQueriesSuggestionsMultiple() { setUpSearchedKeywords("q", "a b"); List<SuggestionDisplayContext> suggestionDisplayContexts = buildRelatedQueriesSuggestions(Arrays.asList("a C", "a b C")); Assert.assertEquals( suggestionDisplayContexts.toString(), 2, suggestionDisplayContexts.size()); assertSuggestion( "a [C] | q=a b(q<<a C)", suggestionDisplayContexts.get(0)); assertSuggestion( "a b [C] | q=a b(q<<a b C)", suggestionDisplayContexts.get(1)); }
@Test public void testGetRelatedSuggestionsWithEmptyList() { setUpSearchedKeywords("q", "a b"); List<SuggestionDisplayContext> suggestionDisplayContexts = buildRelatedQueriesSuggestions(Collections.emptyList()); Assert.assertTrue(suggestionDisplayContexts.isEmpty()); }
@Test public void testGetRelatedSuggestionsWithKeywordsAsSuggestions() { setUpSearchedKeywords("q", "a b"); List<SuggestionDisplayContext> suggestionDisplayContexts = buildRelatedQueriesSuggestions(Arrays.asList("a b", "a b C")); Assert.assertEquals( suggestionDisplayContexts.toString(), 1, suggestionDisplayContexts.size()); assertSuggestion( "a b [C] | q=a b(q<<a b C)", suggestionDisplayContexts.get(0)); }
@Test public void testGetRelatedSuggestionsWithNullSuggestions() { setUpSearchedKeywords("q", "a b"); List<SuggestionDisplayContext> suggestionDisplayContexts = buildRelatedQueriesSuggestions(Arrays.asList(null, "", "a b C")); Assert.assertEquals( suggestionDisplayContexts.toString(), 1, suggestionDisplayContexts.size()); assertSuggestion( "a b [C] | q=a b(q<<a b C)", suggestionDisplayContexts.get(0)); }