public static void searchPane_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { args.Request.SearchSuggestionCollection.AppendQuerySuggestions((from result in Utils.DataManager.searchables where result.resultTitle.ToLower().StartsWith(args.QueryText.ToLower()) orderby result.resultTitle ascending select result.resultTitle).Take(5)); }
void searchPane_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { args.Request.SearchSuggestionCollection.AppendQuerySuggestions((from el in students where el.Name.StartsWith(args.QueryText) orderby el.Name ascending select el.Name).Take(5)); }
void SearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { var vm = ((DashboardViewModel)DataContext); var suggestions = vm.SearchSuggestiongsAsync(args.QueryText); args.Request.SearchSuggestionCollection.AppendQuerySuggestions(suggestions.Result); }
private void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e) { var queryText = e.QueryText; if (string.IsNullOrEmpty(queryText)) { MainPage.Current.NotifyUser("Use the search pane to submit a query", NotifyType.StatusMessage); } else { var request = e.Request; foreach (string suggestion in suggestionList) { if (suggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) { // Add suggestion to Search Pane request.SearchSuggestionCollection.AppendQuerySuggestion(suggestion); // Break since the Search Pane can show at most 25 suggestions if (request.SearchSuggestionCollection.Size >= MainPage.SearchPaneMaxSuggestions) { break; } } } if (request.SearchSuggestionCollection.Size > 0) { MainPage.Current.NotifyUser("Suggestions provided for query: " + queryText, NotifyType.StatusMessage); } else { MainPage.Current.NotifyUser("No suggestions provided for query: " + queryText, NotifyType.StatusMessage); } } }
void OnSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { string query = args.QueryText.ToLower(); if (suggestionList != null) { List<string> result = suggestionList.FindAll(a => a.Contains(query)); args.Request.SearchSuggestionCollection.AppendQuerySuggestions(result); } }
private async void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e) { var queryText = e.QueryText; if (string.IsNullOrEmpty(queryText)) { MainPage.Current.NotifyUser("Use the search pane to submit a query", NotifyType.StatusMessage); } else if (string.IsNullOrEmpty(UrlTextBox.Text)) { MainPage.Current.NotifyUser("Please enter the web service URL", NotifyType.StatusMessage); } else { // The deferral object is used to supply suggestions asynchronously for example when fetching suggestions from a web service. var request = e.Request; var deferral = request.GetDeferral(); try { // Use the web service Url entered in the UrlTextBox that supports OpenSearch Suggestions in order to see suggestions come from the web service. // See http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.0 for details on OpenSearch Suggestions format. // Replace "{searchTerms}" of the Url with the query string. Task task = GetSuggestionsAsync(Regex.Replace(UrlTextBox.Text, "{searchTerms}", Uri.EscapeDataString(queryText)), request.SearchSuggestionCollection); await task; if (task.Status == TaskStatus.RanToCompletion) { if (request.SearchSuggestionCollection.Size > 0) { MainPage.Current.NotifyUser("Suggestions provided for query: " + queryText, NotifyType.StatusMessage); } else { MainPage.Current.NotifyUser("No suggestions provided for query: " + queryText, NotifyType.StatusMessage); } } } catch (TaskCanceledException) { // We have canceled the task. } catch (FormatException) { MainPage.Current.NotifyUser(@"Suggestions could not be retrieved, please verify that the URL points to a valid service (for example http://contoso.com?q={searchTerms}", NotifyType.ErrorMessage); } catch (Exception) { MainPage.Current.NotifyUser("Suggestions could not be displayed, please verify that the service provides valid OpenSearch suggestions", NotifyType.ErrorMessage); } finally { deferral.Complete(); } } }
void OnSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { string query = args.QueryText.ToLower(); string[] terms = { "salt", "pepper", "water", "egg", "vinegar", "flour", "rice", "sugar", "oil" }; foreach (var term in terms) { if (term.StartsWith(query)) args.Request.SearchSuggestionCollection.AppendQuerySuggestion(term); } }
private void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e) { var queryText = e.QueryText; if (string.IsNullOrEmpty(queryText)) { MainPage.Current.NotifyUser("Use the search pane to submit a query", NotifyType.StatusMessage); } else { var request = e.Request; bool isRecommendationFound = false; foreach (string suggestion in suggestionList) { // TODO: create a recommendation when full hit if (suggestion.CompareTo(queryText) == 0) { // Add recommendation to Search Pane RandomAccessStreamReference image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/windows-sdk.png")); request.SearchSuggestionCollection.AppendResultSuggestion( suggestion, // text to display "found " + suggestion, // details "tag#" + suggestion, // tags usable when called back by ResultSuggestionChosen event image, // image if any "image of " + suggestion // image alternate text ); isRecommendationFound = true; } else // otherwise, this is a suggestion if (suggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) { // Add suggestion to Search Pane request.SearchSuggestionCollection.AppendQuerySuggestion(suggestion); } // Break since the Search Pane can show at most 5 suggestions if (request.SearchSuggestionCollection.Size >= MainPage.SearchPaneMaxSuggestions) { break; } } if (request.SearchSuggestionCollection.Size > 0) { // TODO: show if it is a recommendation or just a partial suggestion string prefix = isRecommendationFound ? "*" : ""; MainPage.Current.NotifyUser(prefix + "Suggestions provided for query: " + queryText, NotifyType.StatusMessage); } else { MainPage.Current.NotifyUser("No suggestions provided for query: " + queryText, NotifyType.StatusMessage); } } }
private void SearchPaneOnSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { var navigator = _container.Resolve<IRtNavigator>(); var result = navigator.GetData<SearchController, SearchResult[]>(c => c.SearchForSuggestions(args.QueryText)); args.Request.SearchSuggestionCollection.AppendQuerySuggestions( result.Data .OrderBy(r => r.Description) .Select(r => r.Description) .Distinct()); }
private async void searchPane_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { if (args.QueryText.Length >= 2) { var linkService = ServiceLocator.Current.GetInstance<ILinkService>(); SearchPaneSuggestionsRequestDeferral deferral = args.Request.GetDeferral(); List<Link> results = await linkService.Search(args.QueryText); List<string> searchResults = results.Select(s => s.Name).ToList(); args.Request.SearchSuggestionCollection.AppendQuerySuggestions(searchResults); deferral.Complete(); } }
void searchPanel_SuggestionsRequested(SearchPane s, SearchPaneSuggestionsRequestedEventArgs e) { //provide search suggestions to the search pane //http://weblogs.asp.net/nmarun/archive/2012/09/28/implementing-search-contract-in-windows-8-application.aspx IEnumerable<string> names = from suggestion in ((App)App.Current).AvailableStations where suggestion.Title.StartsWith(e.QueryText, StringComparison.CurrentCultureIgnoreCase) select suggestion.Title; // Take(5) is implemented because the SearchPane // can show a maximum of 5 suggestions // passing a larger collection will only show the first 5 e.Request.SearchSuggestionCollection.AppendQuerySuggestions(names.Take(5)); }
private async void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e) { var queryText = e.QueryText; if (string.IsNullOrEmpty(queryText)) { MainPage.Current.NotifyUser("Use the search pane to submit a query", NotifyType.StatusMessage); } else { // The deferral object is used to supply suggestions asynchronously for example when fetching suggestions from a web service. var request = e.Request; var deferral = request.GetDeferral(); StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(exampleResponse); string response = await FileIO.ReadTextAsync(file); JsonArray parsedResponse = JsonArray.Parse(response); if (parsedResponse.Count > 1) { parsedResponse = JsonArray.Parse(parsedResponse[1].Stringify()); foreach (JsonValue value in parsedResponse) { request.SearchSuggestionCollection.AppendQuerySuggestion(value.GetString()); if (request.SearchSuggestionCollection.Size >= MainPage.SearchPaneMaxSuggestions) { break; } } } if (request.SearchSuggestionCollection.Size > 0) { MainPage.Current.NotifyUser("Suggestions provided for query: " + queryText, NotifyType.StatusMessage); } else { MainPage.Current.NotifyUser("No suggestions provided for query: " + queryText, NotifyType.StatusMessage); } deferral.Complete(); } }
public async void OnSearchPaneSuggestionsRequested(object sender, SearchPaneSuggestionsRequestedEventArgs args) { List<Location> cacheList = await LocationService.GetLocationsFromCache(); List<string> suggestionList = (from location in cacheList select location.City).ToList(); foreach (string suggestion in suggestionList) { if (suggestion.StartsWith(args.QueryText, StringComparison.CurrentCultureIgnoreCase)) { // Add suggestion to Search Pane args.Request.SearchSuggestionCollection.AppendQuerySuggestion(suggestion); } // Break since the Search Pane can show at most 5 suggestions if (args.Request.SearchSuggestionCollection.Size >= 5) { break; } } }
private async void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e) { var queryText = e.QueryText; if (string.IsNullOrEmpty(queryText)) { MainPage.Current.NotifyUser("Use the search pane to submit a query", NotifyType.StatusMessage); } else { var url = "http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search={searchTerms}"; // The deferral object is used to supply suggestions asynchronously for example when fetching suggestions from a web service. var request = e.Request; var deferral = request.GetDeferral(); try { Task task = GetSuggestionsAsync(Regex.Replace(url, "{searchTerms}", Uri.EscapeDataString(queryText)), request.SearchSuggestionCollection); //Debug.WriteLine("* created task {0} query: {1}", task.Id, queryText); await task; //Debug.WriteLine("@ await returned, id {0} status {1} ", task.Id, task.Status); if (task.Status == TaskStatus.RanToCompletion) { if (request.SearchSuggestionCollection.Size > 0) { MainPage.Current.NotifyUser("Suggestions provided for query: " + queryText, NotifyType.StatusMessage); } else { MainPage.Current.NotifyUser("No suggestions provided for query: " + queryText, NotifyType.StatusMessage); } } } catch (TaskCanceledException) { // We have canceled the task. } catch (FormatException) { MainPage.Current.NotifyUser(@"Suggestions could not be retrieved, please verify that the URL points to a valid service (for example http://contoso.com?q={searchTerms}", NotifyType.ErrorMessage); } catch (Exception) { MainPage.Current.NotifyUser("Suggestions could not be displayed, please verify that the service provides valid OpenSearch suggestions", NotifyType.ErrorMessage); } finally { deferral.Complete(); } } }
private async void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e) { var queryText = e.QueryText; if (string.IsNullOrEmpty(queryText)) { MainPage.Current.NotifyUser("Use the search pane to submit a query", NotifyType.StatusMessage); } else { var url = "http://en.wikipedia.org/w/api.php?action=opensearch&format=xml&search={searchTerms}"; // The deferral object is used to supply suggestions asynchronously for example when fetching suggestions from a web service. var request = e.Request; var deferral = request.GetDeferral(); try { // Use the web service Url entered in the UrlTextBox that supports XML Search Suggestions in order to see suggestions come from the web service. // See http://msdn.microsoft.com/en-us/library/cc848863(v=vs.85).aspx for details on XML Search Suggestions format. // Replace "{searchTerms}" of the Url with the query string. Task task = GetSuggestionsAsync(Regex.Replace(url, "{searchTerms}", Uri.EscapeDataString(queryText)), request.SearchSuggestionCollection); await task; if (task.Status == TaskStatus.RanToCompletion) { if (request.SearchSuggestionCollection.Size > 0) { MainPage.Current.NotifyUser("Suggestions provided for query: " + queryText, NotifyType.StatusMessage); } else { MainPage.Current.NotifyUser("No suggestions provided for query: " + queryText, NotifyType.StatusMessage); } } } catch (TaskCanceledException) { // Previous suggestion request was canceled. } catch (FormatException) { MainPage.Current.NotifyUser("Suggestions could not be retrieved, please verify that the URL points to a valid service (for example http://contoso.com?q={searchTerms})", NotifyType.ErrorMessage); } catch (Exception) { MainPage.Current.NotifyUser("Suggestions could not be displayed, please verify that the service provides valid XML Search Suggestions.", NotifyType.ErrorMessage); } finally { deferral.Complete(); } } }
private async void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e) { var queryText = e.QueryText; if (string.IsNullOrEmpty(queryText)) { MainPage.Current.NotifyUser("Use the search pane to submit a query", NotifyType.StatusMessage); } else { // The deferral object is used to supply suggestions asynchronously for example when fetching suggestions from a web service. var request = e.Request; var deferral = request.GetDeferral(); StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(exampleResponse); await this.GenerateSuggestions(file, request.SearchSuggestionCollection); if (request.SearchSuggestionCollection.Size > 0) { MainPage.Current.NotifyUser("Suggestions provided for query: " + queryText, NotifyType.StatusMessage); } else { MainPage.Current.NotifyUser("No suggestions provided for query: " + queryText, NotifyType.StatusMessage); } deferral.Complete(); } }
private async void SearchPaneSuggestionsRequested( SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { SearchPaneSuggestionsRequestDeferral deferral = args.Request.GetDeferral(); GeocodeRequestOptions requests = new GeocodeRequestOptions(args.QueryText); _searchManager = MapView.SearchManager; _searchResponse = await _searchManager.GeocodeAsync(requests); foreach (GeocodeLocation locationData in _searchResponse.LocationData) args.Request.SearchSuggestionCollection.AppendQuerySuggestion(locationData.Address.FormattedAddress); deferral.Complete(); }
void SearchPane_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { try { //var q = from c in file // where c.DisplayName.ToLower().Contains(args.QueryText.ToLower()) // select c.DisplayName; var g = (from x in Collections where x.DisplayName.ToLower().Contains(args.QueryText.ToLower()) select x.DisplayName).Distinct(); foreach (var s in g) { args.Request.SearchSuggestionCollection.AppendQuerySuggestion(s); } } catch { ErrorCorrecting("010"); } }
/// <summary> /// Adds up to 5 search suggestions. /// </summary> /// <param name="sender">Search Pane.</param> /// <param name="args">Contains the QueryText.</param> private void OnSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { int count = 0; string searchText = args.QueryText.ToLower(); foreach (string term in this.searchTerms) { if (term.ToLower().IndexOf(searchText) == 0) { count++; args.Request.SearchSuggestionCollection.AppendQuerySuggestion(term); if (++count == 5) { return; } } } }
void SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { var result = GetSuggestionsFrom(args.QueryText).Take(5); foreach (var suggestion in result) args.Request.SearchSuggestionCollection.AppendQuerySuggestion(suggestion); }
private void App_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { string query = args.QueryText.ToLower(); var allQuery = GamePediaDataSource.GetGroups("AllGroups"); foreach (var group in allQuery.Distinct()) { foreach (var item in group.Items.Distinct()) { if (item.Title.ToLower().StartsWith(query)) args.Request.SearchSuggestionCollection.AppendQuerySuggestion(item.Title); } } }
private async void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { var frame = Window.Current.Content as Frame; if (frame != null) { var searchResultsPage = frame.Content as MainPage; if (searchResultsPage != null) { var viewModel = searchResultsPage.DataContext as SearchResultsPageControlViewModel; if (viewModel != null) { args.Request.SearchSuggestionCollection.AppendQuerySuggestions(await viewModel.GetSuggestionsAsync(args.QueryText)); } } } }
private void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e) { var queryText = e.QueryText.ToLower(); if (string.IsNullOrEmpty(queryText)) { return; } var maxSuggestions = 5; var request = e.Request; var source = new DataSource(); var matchingTeams = source.MatchingTeams(queryText); foreach (var team in matchingTeams) { request.SearchSuggestionCollection.AppendQuerySuggestion(team.Name); if (request.SearchSuggestionCollection.Size >= maxSuggestions) { return; } } var matchingGroups = source.MatchingGroups(queryText); foreach (var grp in matchingGroups) { request.SearchSuggestionCollection.AppendQuerySuggestion(grp.Name); if (request.SearchSuggestionCollection.Size >= maxSuggestions) { return; } } }
private void Results_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { var queryText = args.QueryText.ToLower(); var request = args.Request; List<string> suggestionList = new List<string>() { "Pi", "Pi2", "Pumpkin Pie", "Pineapples", "Apple Pie", "Brown Garden Snail", "Doppler Effect", "5", "5 Factorial", "y = 3x^2", "y = 1/(3x)" }; if (string.IsNullOrEmpty(queryText)) { //MainPage.Current.NotifyUser("Use the search pane to submit a query", NotifyType.StatusMessage); } else { foreach (string suggestion in suggestionList) { if (suggestion.ToLower().Contains(queryText)) { // Add suggestion to Search Pane request.SearchSuggestionCollection.AppendQuerySuggestion(suggestion); // Break since the Search Pane can show at most 5 suggestions if (request.SearchSuggestionCollection.Size >= 5) { break; } } } } if (request.SearchSuggestionCollection.Size > 0) { //MainPage.Current.NotifyUser("Suggestions provided for query: " + queryText, NotifyType.StatusMessage); } else { //MainPage.Current.NotifyUser("No suggestions provided for query: " + queryText, NotifyType.StatusMessage); } }
void searchPane_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { foreach (ForumItem forumItem in viewModel.ForumItemList) { string suggestion = forumItem.Name; if (suggestion.StartsWith(args.QueryText, StringComparison.CurrentCultureIgnoreCase)) { args.Request.SearchSuggestionCollection.AppendQuerySuggestion(suggestion); } if (args.Request.SearchSuggestionCollection.Size >= 5) { break; } } }
/// <summary> /// Called when search pane suggestions are requested. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="SearchPaneSuggestionsRequestedEventArgs"/> instance containing the event data.</param> private async void OnSearchPaneSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs e) { var queryText = e.QueryText; if (!string.IsNullOrEmpty(queryText)) { // The deferral object is used to supply suggestions asynchronously for example when fetching suggestions from a web service. var deferral = e.Request.GetDeferral(); try { Debug.WriteLine("Requesting suggestions for query: " + queryText); ListResponse<string> suggestions = await ApiClient.GetSearchSuggestionsAsync(queryText, 5); if (suggestions.Result != null) { e.Request.SearchSuggestionCollection.AppendQuerySuggestions(suggestions.Result); Debug.WriteLine("Suggestions provided for query: " + queryText); } else { Debug.WriteLine("No suggestions provided for query: " + queryText + " error: " + suggestions.Error.Message); } } catch (Exception) { Debug.WriteLine("Suggestions could not be displayed"); } finally { deferral.Complete(); } } }
// // http://blog.falafel.com/Blogs/john-waters/2012/10/10/doing-an-asynchronous-search-in-windows-8 // async void OnSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { string query = args.QueryText.ToLower(); var deferral = args.Request.GetDeferral(); try { var ctx = new RisDbContext(); var matches = await ctx.GetHistoryEntriesStartingWith(query); args.Request.SearchSuggestionCollection.AppendQuerySuggestions(matches); } finally { deferral.Complete(); } }
async void search_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { var deferral = args.Request.GetDeferral(); try { await SearchInteractionHelper.PopulateSuggestionsAsync(args.QueryText, args.Request.SearchSuggestionCollection); } finally { deferral.Complete(); } }
//添加改变选中项的方法并推送到UI void searchPane_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args) { foreach (singer temp in vmodel.MyList) { string MaybeRight = temp.Title; if (MaybeRight.StartsWith(args.QueryText, StringComparison.CurrentCultureIgnoreCase)) { args.Request.SearchSuggestionCollection.AppendQuerySuggestion(MaybeRight); } } }
private void DoWikipediaSearch(SearchPaneSuggestionsRequestedEventArgs request) { MainPage.Current.NotifyUser("Searching for: " + request.QueryText, NotifyType.StatusMessage); var deferral = request.Request.GetDeferral(); request.Request.SearchSuggestionCollection.AppendQuerySuggestion("FOoo"); //var resultArray = await SearchWikipediaAsync(request.QueryText); //addToSearchResults( // resultArray, // request.Request.SearchSuggestionCollection, // MainPage.SearchPaneMaxSuggestions); deferral.Complete(); }