Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SearchSuggestionCollection class

Applies to Windows only

Represents a collection of search suggestions to be displayed in the search pane in response to a suggestionsrequested event.

Syntax


var searchSuggestionCollection = searchPaneSuggestionsRequested.searchSuggestionCollection;

Attributes

[MarshalingBehavior(Agile)]
[Muse()]
[Version(0x06020000)]

Members

The SearchSuggestionCollection class has these types of members:

Methods

The SearchSuggestionCollection class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
AppendQuerySuggestion Appends a query suggestion to the list of search suggestions for the search pane.
AppendQuerySuggestions Appends a list of query suggestions to the list of search suggestions for the search pane.
AppendResultSuggestion Appends a suggested search result to the list of suggestions to display in the search pane.
AppendSearchSeparator Appends a text label that is used to separate groups of suggestions in the search pane.

 

Properties

The SearchSuggestionCollection class has these properties.

PropertyAccess typeDescription

Size

Read-onlyThe number of suggestions in the collection.

 

Remarks

The search pane can display 5 suggestions, at most. Additionally, each separator you use takes the place of a suggestion and lowers the number of suggestions that you can display. Learn more about displaying suggestions in Guidelines and checklist for search.

An app retrieves this object through the searchPaneSuggestionsRequest.searchSuggestionCollection property while handling a suggestionsrequested event.

Examples

The Search contract sample demonstrates how to respond to a suggestionsrequested event, including how to use the searchSuggestionCollection.


// Register the onsuggestionsrequested event in your apps global scope, for example default.js, so that it is registered as soon as your app is launched.
Windows.ApplicationModel.Search.SearchPane.getForCurrentView().onsuggestionsrequested = function (eventObject) {
    var queryText = eventObject.queryText, suggestionRequest = eventObject.request, linguisticDetails = eventObject.linguisticDetails;

    var queryAlternatives = linguisticDetails.queryTextAlternatives;
    var maxNumberOfSuggestions = 5;
    for (var i = 0, len = queryAlternatives.length, done = false; i < len && !done; i++) {
        // toLowerCase not necessary for East Asian languages. Preserves compatibility when non East Asian suggestions are mixed in with East Asian suggestions.
        var alternative = queryAlternatives[i].toLowerCase();
        for (var j = 0, suggestionLength = suggestionList.length; j < suggestionLength; j++) {
            if (suggestionList[j].substr(0, alternative.length).toLowerCase() === alternative) {
                suggestionRequest.searchSuggestionCollection.appendQuerySuggestion(suggestionList[j]);
                if (suggestionRequest.searchSuggestionCollection.size === maxNumberOfSuggestions) {
                    done = true;
                    break;
                }
            }
        }
    }

    // Construct list of alternatives so we can output them.
    var alternatives = "";
    for (var k = 0, alternativeCount = queryAlternatives.length; k < alternativeCount; k++) {
        alternatives += queryAlternatives[k];
    }
    if (suggestionRequest.searchSuggestionCollection.size > 0) {
        WinJS.log && WinJS.log("Suggestions provided for query: " + queryText + "\nUsing alternatives: " + alternatives, "sample", "status");
    } else {
        WinJS.log && WinJS.log("No suggestions provided for query: " + queryText + "\nUsing alternatives: " + alternatives, "sample", "status");
    }
};


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

None supported

Namespace

Windows.ApplicationModel.Search
Windows::ApplicationModel::Search [C++]

Metadata

Windows.winmd

See also

Search contract sample
Guidelines and checklist for search
Reference
SearchPane.SuggestionsRequested event
SearchPaneSuggestionsRequestedEventArgs class
SearchPaneSuggestionsRequestedEventArgs.Request property
SearchPaneSuggestionsRequest class
SearchPaneSuggestionsRequest.SearchSuggestionCollection property

 

 

Show:
© 2014 Microsoft