private async Task GetSuggestionsAsync(string str, SearchSuggestionCollection suggestions) { // Cancel the previous suggestion request if it is not finished. if (currentHttpTask != null) { currentHttpTask.AsAsyncOperation <string>().Cancel(); //Debug.WriteLine(" - cancelling task {0} status: {1}", currentHttpTask.Id, currentHttpTask.Status); } // Get the suggestions from an open search service. currentHttpTask = httpClient.GetStringAsync(str); Debug.WriteLine(" + task created, id: {0} string: {1}", currentHttpTask.Id, str); string response = await currentHttpTask; // inject a delay to simulate the time for the web response await Task.Delay(rand.Next(50, 6000)); JsonArray parsedResponse = JsonArray.Parse(response); if (parsedResponse.Count > 1) { foreach (JsonValue value in parsedResponse[1].GetArray()) { suggestions.AppendQuerySuggestion(value.GetString()); //Debug.WriteLine("\n Search Result ({0}): {1}", str, value.GetString()); if (suggestions.Size >= MainPage.SearchPaneMaxSuggestions) { break; } } } }
private async Task GetSuggestionsAsync(string str, SearchSuggestionCollection suggestions) { // Cancel the previous suggestion request if it is not finished. if (currentHttpTask != null) { currentHttpTask.AsAsyncOperation <string>().Cancel(); } // Get the suggestions from an open search service. currentHttpTask = httpClient.GetStringAsync(str); string response = await currentHttpTask; JsonArray parsedResponse = JsonArray.Parse(response); if (parsedResponse.Count > 1) { foreach (JsonValue value in parsedResponse[1].GetArray()) { suggestions.AppendQuerySuggestion(value.GetString()); if (suggestions.Size >= MainPage.SearchPaneMaxSuggestions) { break; } } } }
public AppendToSearchSuggestionCollectionVisitor(SearchSuggestionCollection collection) { if (collection == null) { throw new ArgumentNullException("collection"); } _collection = collection; }
private void MainPage_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { SearchSuggestionCollection coll = args.Request.SearchSuggestionCollection; if (args.QueryText.StartsWith("c", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("Carolla"); coll.AppendQuerySuggestion("Carmy carolla"); coll.AppendQuerySuggestion("Carmy Highbrid"); coll.AppendQuerySuggestion("Concept vehicles"); } else if (args.QueryText.StartsWith("4", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("4 Runner"); coll.AppendQuerySuggestion("Runner Flat"); } else if (args.QueryText.StartsWith("h", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("High Lander"); coll.AppendQuerySuggestion("High Lander Brid"); } else if (args.QueryText.StartsWith("l", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("Land Cruiser"); coll.AppendQuerySuggestion("Runner Flat"); } else if (args.QueryText.StartsWith("t", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("Tacoma"); coll.AppendQuerySuggestion("Tundra"); } else if (args.QueryText.StartsWith("r", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("Rav 4"); } else if (args.QueryText.StartsWith("s", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("Sienna"); coll.AppendQuerySuggestion("Sequaio"); } else if (args.QueryText.StartsWith("a", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("Avalon"); coll.AppendQuerySuggestion("Avalon Hybrid"); } else if (args.QueryText.StartsWith("p", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("Prius"); coll.AppendQuerySuggestion("Prius C"); coll.AppendQuerySuggestion("Prius V"); } else if (args.QueryText.StartsWith("y", StringComparison.CurrentCultureIgnoreCase)) { coll.AppendQuerySuggestion("Yaris"); coll.AppendQuerySuggestion("Yaris C"); coll.AppendQuerySuggestion("Yaris V"); } }
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); } }
private void addToSearchResults(JsonArray jsonArray, SearchSuggestionCollection suggestionResult, int maxResults) { if (jsonArray.Count > 1) { foreach (JsonValue value in jsonArray[1].GetArray()) { suggestionResult.AppendQuerySuggestion(value.GetString()); Debug.WriteLine("Suggestion: " + value.GetString()); if (suggestionResult.Size >= MainPage.SearchPaneMaxSuggestions) { break; } } } }
public void GetSeachSuggestions(string searchString, SearchSuggestionCollection suggestions) { if (searchString != "") { foreach (var folder in FolderCollection) { var searchCollection = folder.Value.Items. Where(sf => (sf.Title.myContains(searchString, StringComparison.OrdinalIgnoreCase) || sf.URL.myContains(searchString, StringComparison.OrdinalIgnoreCase))); foreach (SkyDriveFile file in searchCollection) { suggestions.AppendQuerySuggestion(file.Title + " | " + file.URL); } } } }
private void mysearchBox_SuggestionsRequested(Windows.UI.Xaml.Controls.SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args) { SearchSuggestionCollection search = args.Request.SearchSuggestionCollection; if (args.QueryText.StartsWith("a", StringComparison.CurrentCultureIgnoreCase)) { search.AppendQuerySuggestion("Apple"); search.AppendQuerySuggestion("Almonds"); search.AppendQuerySuggestion("Anmimals"); } else if (args.QueryText.StartsWith("b", StringComparison.CurrentCultureIgnoreCase)) { search.AppendQuerySuggestion("Banana"); search.AppendQuerySuggestion("Bat"); } }
private void championSearchBox_SuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args) { string search = args.QueryText; if (search != "") { SearchSuggestionCollection suggestionCollegion = args.Request.SearchSuggestionCollection; championsCollection.Clear(); foreach (KeyValuePair <string, ChampionStatic> champion in sortedChampions) { if (champion.Value.name.ToLower().Contains(search.ToLower())) { if (selectedRole == "All") { suggestionCollegion.AppendQuerySuggestion(champion.Value.name); if (screenHeight >= 1440) { championsCollection.Add(new ChampionsGridViewBinding(new Uri(AppConstants.championLoadingUrl + champion.Key + "_0.jpg"), 308, 560, champion.Key, champion.Value)); } else { championsCollection.Add(new ChampionsGridViewBinding(new Uri(AppConstants.ChampionIconUrl() + champion.Key + ".png"), 120, 120, champion.Key, champion.Value)); } } else { if (champion.Value.tags[0] == selectedRole) { suggestionCollegion.AppendQuerySuggestion(champion.Value.name); if (screenHeight >= 1440) { championsCollection.Add(new ChampionsGridViewBinding(new Uri(AppConstants.championLoadingUrl + champion.Key + "_0.jpg"), 308, 560, champion.Key, champion.Value)); } else { championsCollection.Add(new ChampionsGridViewBinding(new Uri(AppConstants.ChampionIconUrl() + champion.Key + ".png"), 120, 120, champion.Key, champion.Value)); } } } } } } else { RefreshChampionsCollection(); } }
private async Task GetSuggestionsAsync(string str, SearchSuggestionCollection suggestions) { // Cancel the previous suggestion request if it is not finished. if (currentXmlRequestOp != null) { currentXmlRequestOp.Cancel(); } // Get the suggestion from a web service. currentXmlRequestOp = XmlDocument.LoadFromUriAsync(new Uri(str)); XmlDocument doc = await currentXmlRequestOp; await Task.Delay(rand.Next(10, 5000)); Debug.WriteLine("** response size: {0}", doc.GetXml().Length); currentXmlRequestOp = null; XmlNodeList nodes = doc.GetElementsByTagName("Section"); if (nodes.Count > 0) { IXmlNode section = nodes[0]; foreach (IXmlNode node in section.ChildNodes) { if (node.NodeType != NodeType.ElementNode) { continue; } if (node.NodeName.Equals("Separator", StringComparison.CurrentCultureIgnoreCase)) { string title = null; IXmlNode titleAttr = node.Attributes.GetNamedItem("title"); if (titleAttr != null) { title = titleAttr.NodeValue.ToString(); } suggestions.AppendSearchSeparator(string.IsNullOrWhiteSpace(title) ? "Suggestions" : title); } else { AddSuggestionFromNode(node, suggestions); } } } }
/// <summary> /// Completes the retreval of suggestions from the web service /// </summary> /// <param name="str">User query string</param> /// <param name="suggestions">Suggestions list to append new suggestions</param> /// <returns></returns> private async Task GetSuggestionsAsync(string str, SearchSuggestionCollection suggestions) { // Cancel the previous suggestion request if it is not finished. if (currentHttpTask != null) { currentHttpTask.AsAsyncOperation <string>().Cancel(); } // Get the suggestions from an open search service. currentHttpTask = httpClient.GetStringAsync(str); string response = await currentHttpTask; JsonObject jsonObject = JsonObject.Parse(response); jsonObject.ContainsKey("data"); String test1 = jsonObject["data"].GetString(); string[] test = test1.Split('|'); foreach (string value in test) { suggestions.AppendQuerySuggestion(value); } }
public SearchSuggestion(SearchSuggestionCollection searchSuggestionApi) { Description = searchSuggestionApi.Output; }
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); } }