private void FilterNotes(string searchText) { ArchivedNotes.Clear(); if (searchText == string.Empty) { ArchivedNotes.AddRange(shadowNotes.OrderByDescending(x => x.ArchivedDate)); } else { var matches = shadowNotes.Select(x => { short score = 0; if (x.Name.ToLowerInvariant().Contains(searchText)) { score += 2; } if (x.Content.ToLowerInvariant().Contains(searchText)) { score += 1; } return(new { Score = score, Note = x }); }) .Where(x => x.Score > 0) .OrderByDescending(x => x.Score) .ThenByDescending(x => x.Note.ArchivedDate) .Select(x => x.Note); ArchivedNotes.AddRange(matches); } }
private void ClearSearch() { SearchText = string.Empty; ArchivedNotes.Clear(); ArchivedNotes.AddRange(shadowNotes.OrderByDescending(x => x.ArchivedDate)); previousSearchText = string.Empty; }