private void CheckNewSearchString() { if (forceNewSearch || SearchString != localSearchString && !currentlySearching) { forceNewSearch = false; currentlySearching = true; localSearchString = SearchString; var sw = new Stopwatch(); sw.Start(); SelectedIndex = -1; List <RunItem> list = Indexing.Search(localSearchString); Application.Current.Dispatcher.Invoke(() => { SearchSuggestions.RaiseListChangedEvents = false; SearchSuggestions.Clear(); foreach (var item in list) { SearchSuggestions.Add(item); } SearchSuggestions.RaiseListChangedEvents = true; SearchSuggestions.ResetBindings(); }, DispatcherPriority.Background); sw.Stop(); RenderingTime = (int)sw.ElapsedMilliseconds; currentlySearching = false; } }
private async Task UpdateSearchSuggestionsInner(string partialSearchQuery, CancellationToken cancellationToken) { IList <SearchSuggestionViewModel> suggestions; bool reverseSearch; try { await querySemaphore.WaitAsync(cancellationToken); (suggestions, reverseSearch) = await GetSearchSuggestions(partialSearchQuery, cancellationToken); } catch (OperationCanceledException) { suggestions = null; reverseSearch = false; } finally { querySemaphore.Release(); } if (suggestions != null) { UpdateSearchSuggestions(suggestions, reverseSearch); } else { SearchSuggestions.Clear(); } }
/// <summary> /// Get a list of search query suggestions. /// </summary> public async Task GetSearchSuggestions() { var query = Query != null?Query.Trim() : null; if (String.IsNullOrWhiteSpace(query)) { return; } var suggestions = await searchService.GetSearchSuggestionsAsync(Query); SearchSuggestions.Clear(); foreach (var suggestion in suggestions) { SearchSuggestions.Add(suggestion.Value); } }
private async Task PullSearchSuggestionAsync(bool userChangedQuery) { if (!userChangedQuery) { return; } var query = SearchQuery; if (string.IsNullOrEmpty(query)) { SearchResultsAvailable = false; SearchSuggestions.Clear(); SearchSuggestions.Add(new TraktShow { Title = "No result" }); return; } var searchResults = await _client.Search.GetTextQueryResultsAsync(TraktSearchResultType.Show, query); var tasks = searchResults .Select(result => result.Show.Ids.Trakt.ToString()) .Select(showId => _client.Shows.GetShowAsync(showId, new TraktExtendedOption { Full = true, Images = true })) .ToList(); var fullShows = await Task.WhenAll(tasks); if (fullShows.Any()) { SearchSuggestions.Clear(); SearchSuggestions.AddRange(fullShows); } else { SearchSuggestions.Clear(); SearchSuggestions.Add(new TraktShow { Title = "No result" }); } }
public async Task PerformQuery(string searchQuery, bool dontSearchInBothDirections = false) { if (searchSuggestionCancellationTokenSource != null) { searchSuggestionCancellationTokenSource.Cancel(); } try { await querySemaphore.WaitAsync(); // it may happen that the AutoSuggestBox does not hide search suggestions automatically after // performing a query. For these cases, clear the suggestions manually SearchSuggestions.Clear(); Task <List <DictionaryEntry> > searchTask = PerformQueryInner(searchQuery, dontSearchInBothDirections); Task animationDelayTask = Task.Delay(250); Task finishedTask = await Task.WhenAny(searchTask, animationDelayTask); if (finishedTask == animationDelayTask) { IsSearchInProgress = true; await searchTask; } SearchContext searchContext = new SearchContext(searchQuery, selectedDirection, dontSearchInBothDirections); List <DictionaryEntry> results = searchTask.Result; DictionaryEntries = new LazyCollection <DictionaryEntry, DictionaryEntryViewModel>( results, entry => new DictionaryEntryViewModel(entry, searchContext)); } finally { IsSearchInProgress = false; querySemaphore.Release(); } }
public async Task ClearStateAsync() { SearchSuggestions.Clear(); Shows.Clear(); await PerformSearchQueryAsync(null); }