示例#1
0
        private void AddSuggestionFromNode(IXmlNode node, SearchSuggestionCollection suggestions)
        {
            string text        = "";
            string description = "";
            string url         = "";
            string imageUrl    = "";
            string imageAlt    = "";

            foreach (IXmlNode subNode in node.ChildNodes)
            {
                if (subNode.NodeType != NodeType.ElementNode)
                {
                    continue;
                }
                if (subNode.NodeName.Equals("Text", StringComparison.CurrentCultureIgnoreCase))
                {
                    text = subNode.InnerText;
                }
                else if (subNode.NodeName.Equals("Description", StringComparison.CurrentCultureIgnoreCase))
                {
                    description = subNode.InnerText;
                }
                else if (subNode.NodeName.Equals("Url", StringComparison.CurrentCultureIgnoreCase))
                {
                    url = subNode.InnerText;
                }
                else if (subNode.NodeName.Equals("Image", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (subNode.Attributes.GetNamedItem("source") != null)
                    {
                        imageUrl = subNode.Attributes.GetNamedItem("source").InnerText;
                    }
                    if (subNode.Attributes.GetNamedItem("alt") != null)
                    {
                        imageAlt = subNode.Attributes.GetNamedItem("alt").InnerText;
                    }
                }
            }

            if (string.IsNullOrWhiteSpace(text))
            {
                // No proper suggestion item exists
            }
            else if (string.IsNullOrWhiteSpace(url))
            {
                suggestions.AppendQuerySuggestion(text);
            }
            else
            {
                // The following image should not be used in your application for Result Suggestions.  Replace the image with one that is tailored to your content
                Uri uri = string.IsNullOrWhiteSpace(imageUrl) ? new Uri("ms-appx:///Assets/SDK_ResultSuggestionImage.png") : new Uri(imageUrl);
                RandomAccessStreamReference imageSource = RandomAccessStreamReference.CreateFromUri(uri);
                suggestions.AppendResultSuggestion(text, description, url, imageSource, imageAlt);
                Debug.WriteLine("\n                   Search Result ({0}): {1}", text, description);
            }
        }
 public void Visit(SearchResultSuggestion suggestion)
 {
     _collection.AppendResultSuggestion(suggestion.Text, suggestion.DetailText, suggestion.Tag, suggestion.Image, suggestion.ImageAlternateText);
 }
示例#3
0
        public static async Task PopulateSuggestionsAsync(string queryText, SearchSuggestionCollection results)
        {
            // if we don't have at least three characters to work with, do nothing...
            if (queryText.Length < 3)
            {
                return;
            }

            // how many?
            int maxSuggestions = 5;

            // get the list...
            var suggestions = await ReportItem.GetSearchSuggestionsAsync(queryText);

            // sort the suggestions...
            var titles = new List <string>();

            foreach (var title in suggestions.Keys)
            {
                titles.Add(title);
            }
            titles.Sort();

            // do we have one that we can use as a recommendation?
            ReportItem recommendation = null;

            foreach (var title in titles)
            {
                if (suggestions[title].Count == 1)
                {
                    recommendation = suggestions[title][0];
                    break;
                }
            }

            // if we have a recommendation only show three suggestions...
            if (recommendation != null)
            {
                maxSuggestions -= 2;
            }

            // add the suggestions...
            foreach (var title in titles)
            {
                results.AppendQuerySuggestion(title);

                // enough?
                if (results.Size == maxSuggestions)
                {
                    break;
                }
            }

            // add the recommendation...
            if (recommendation != null)
            {
                // we need an image...
                var viewItem = new ReportViewItem(recommendation);
                var imageUri = await new ReportImageCacheManager().GetLocalImageUriAsync(viewItem);

                // add the suggestion...
                results.AppendSearchSeparator("Recommendation");
                results.AppendResultSuggestion(recommendation.Title, recommendation.Description, recommendation.Id.ToString(),
                                               RandomAccessStreamReference.CreateFromUri(new Uri(imageUri)), recommendation.Title);
            }
        }