public SpellCheckerViewModel(ISpellCheckerModel spellChecker) { _spellChecker = spellChecker; _dispatcher = new DispatcherScheduler(System.Windows.Threading.Dispatcher.CurrentDispatcher); _corrections = new BindingList <string>(); _logs = new BindingList <string>(); _searchChanged = new Subject <string>(); _logChanged = new Subject <string>(); Func <string, IObservable <string> > GetSuggestions = (searchText) => { IsProcessing = true; Corrections.Clear(); Error = null; AddToLog(string.Format("Searching for suggestions : {0}", searchText)); return(_spellChecker .SpellCheck(searchText, 5) .ToObservable <string>()); }; var searches = _searchChanged .Select(GetSuggestions) .Finally(() => AddToLog("Search DISPOSED!!!")); searches .Switch() .Where(s => s.Length > 3) .DistinctUntilChanged() .SubscribeOn(Scheduler.Default) .ObserveOn(_dispatcher) .Subscribe(OnEachSuggest, OnSuggestError, OnSuggestComplete); DoLogging(_logChanged); }
private IObservable <string> GetSuggestions(string searchText) { IsProcessing = true; Corrections.Clear(); Error = null; AddToLog(string.Format("Searching for suggestions : {0}", searchText)); return(_spellChecker.SpellCheck(searchText, 5).ToObservable <string>()); }
public SpellCheckerViewModel(ISpellCheckerModel spellChecker) { _spellChecker = spellChecker; _dispatcher = new DispatcherScheduler(System.Windows.Threading.Dispatcher.CurrentDispatcher); _corrections = new BindingList <string>(); _searchChanged = new Subject <string>(); Func <string, IObservable <string> > GetSuggestions = (searchText) => { IsProcessing = true; Corrections.Clear(); Error = null; return(_spellChecker.SpellCheck(searchText, 5).ToObservable <string>()); }; var searches = this.SearchChanged .Select(GetSuggestions); searches .Switch() //Provides the most recent changes in this sequence .Where(s => s.Length > 3) //Do lookup only for 4 letter words and above .DistinctUntilChanged() //Do lookup only if new value entered is different from old .SubscribeOn(Scheduler.Default) //Search on background thread .ObserveOn(_dispatcher) //Return result on dispatcher .Subscribe(OnEachSuggest, OnSuggestError, OnSuggestComplete); }
// GET api/values public IEnumerable <string> Get([FromUri] SearchContext context) { return(_spellChecker.SpellCheck(context.Lookup, context.Count)); }