public async Task <long> Search(UIState state, string query) { Log.WriteLine("query: {0}", query); _foundArticles.Clear(); string type = state.GetQueryTypeAsName(); switch (type) { case "title": _foundArticles = await SearchTitle(query); break; case "author": _foundArticles = await SearchAuthor(query); break; case "atccode": _foundArticles = await SearchATC(query); break; case "ingredient": _foundArticles = await SearchIngredient(query); break; case "regnr": _foundArticles = await SearchRegNr(query); break; case "application": _foundArticles = await SearchApplication(query); break; case "eancode": _foundArticles = await SearchEanCode(query); break; default: break; } UpdateSearchResults(state); return(_foundArticles.Count); }
public async Task <long> Search(UIState state, string query) { _foundEntries.Clear(); string type = state.GetQueryTypeAsName(); if (type.Equals("fulltext")) { _foundEntries = await SearchFullText(query); } UpdateSearchResults(state); return(_foundEntries.Count); }
// Finds entries in current _foundEntries public async Task <long> Filter(UIState state, string query) { string type = state.GetQueryTypeAsName(); if (type.Equals("fulltext")) { // case insensitive _foundEntries = _foundEntries.Where(e => { string keyword = e.Keyword.ToLower(); return(keyword.Contains(query.ToLower())); }).ToList(); } UpdateSearchResults(state); return(_foundEntries.Count); }
public void UpdateSearchResults(UIState state) { SearchResultItems.Clear(); SearchResultItems.AddRange(state, _foundEntries); }
public void AddRange(UIState uiState, IEnumerable <Article> list) { if (list == null) { throw new ArgumentNullException("list"); } _suppressNotification = true; string type = uiState.GetQueryTypeAsName(); if (type.Equals("title")) { foreach (Article article in list) { if (uiState.IsCompendium || (uiState.IsFavorites && article.IsFavorite) || (uiState.IsPrescriptions)) { List <string> packInfoList = article.PackInfo.Split('\n').ToList(); List <string> packagesList = article.Packages.Split('\n').ToList(); ChildItemsObservableCollection ci = new ChildItemsObservableCollection(); ci.AddRange(article.Id, article.Author.ToLower(), packInfoList, packagesList); Add(new Item() { Id = article.Id, Text = article.Title, IsFavorite = article.IsFavorite, ChildItems = ci }); } else if (uiState.IsInteractions) { // Calculate number of child items (number of packages) var packagesList = article.Packages.Split('\n'); int numPacks = packagesList.Length - 1; string numPackagesStr = "1 Packung"; if (numPacks == 0 || numPacks > 1) { numPackagesStr = string.Format("{0} Packungen", numPacks); } ChildItemsObservableCollection ci = new ChildItemsObservableCollection(); Add(new Item() { Id = article.Id, Text = article.Title, IsFavorite = article.IsFavorite, ChildItems = new ChildItemsObservableCollection { new ChildItem() { Text = numPackagesStr, Color = Colors.SearchBoxChildItems } } }); } } } else if (type.Equals("author")) { foreach (Article article in list) { if (uiState.IsCompendium || uiState.IsInteractions || (uiState.IsFavorites && article.IsFavorite) || uiState.IsPrescriptions) { Add(new Item() { Id = article.Id, Text = article.Title, IsFavorite = article.IsFavorite, ChildItems = new ChildItemsObservableCollection { new ChildItem() { Text = article.Author, Color = Colors.SearchBoxChildItems } } }); } } } else if (type.Equals("atccode")) { foreach (Article article in list) { if (uiState.IsCompendium || (uiState.IsFavorites && article.IsFavorite) || uiState.IsPrescriptions) { ChildItemsObservableCollection ci = new ChildItemsObservableCollection(); // ATC code + ATC name string atcCode = article?.AtcCode.Replace(";", " - "); // ATC class string[] atc1 = article?.AtcClass?.Split(';'); string atcClass = ""; if (atc1 != null) { atcClass = (atc1.Length > 1) ? atc1[1] : ""; } // ATC Subgroup string atcSubClass = (atcClass.Length > 2) ? atc1[2] : ""; string[] atc2 = atcSubClass?.Split('#'); string subGroup = (atc2.Length > 1) ? atc2[1] : ""; List <string> listOfAtcInfo = new List <string> { atcCode, subGroup, atcClass }; ci.AddRange(listOfAtcInfo); Add(new Item() { Id = article.Id, Text = article.Title, IsFavorite = article.IsFavorite, ChildItems = ci }); } else if (uiState.IsInteractions) { ChildItemsObservableCollection ci = new ChildItemsObservableCollection(); // ATC code + ATC name string atcCode = article?.AtcCode.Replace(";", " - "); List <string> listOfAtcInfo = new List <string> { atcCode, "", "" }; ci.AddRange(listOfAtcInfo); Add(new Item() { Id = article.Id, Text = article.Title, IsFavorite = article.IsFavorite, ChildItems = ci }); } } } else if (type.Equals("regnr")) { foreach (Article article in list) { if (uiState.IsCompendium || uiState.IsInteractions || (uiState.IsFavorites && article.IsFavorite) || uiState.IsPrescriptions) { Add(new Item() { Id = article.Id, Text = article.Title, IsFavorite = article.IsFavorite, ChildItems = new ChildItemsObservableCollection { new ChildItem() { Text = article.Regnrs, Color = Colors.SearchBoxChildItems } } }); } } } else if (type.Equals("application")) { foreach (Article article in list) { if (uiState.IsCompendium || uiState.IsInteractions || (uiState.IsFavorites && article.IsFavorite) || uiState.IsPrescriptions) { ChildItemsObservableCollection ci = new ChildItemsObservableCollection(); List <string> listOfApplications = article?.Application.Split(';').ToList(); ci.AddRange(listOfApplications); Add(new Item() { Id = article.Id, Text = article.Title, IsFavorite = article.IsFavorite, ChildItems = ci }); } } } _suppressNotification = false; OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }
// Finds articles in current _foundArticles public async Task <long> Filter(UIState state, string query) { Log.WriteLine("query: {0}", query); string type = state.GetQueryTypeAsName(); _foundArticles = _foundArticles.Where(a => { string key = ""; switch (type) { // case insensitive filter case "title": if (a.Title != null) { key = a.Title.ToLower(); } break; case "author": if (a.Author != null) { key = a.Author.ToLower(); } break; case "atccode": if (a.AtcCode != null) { key = a.AtcCode.ToLower(); } break; case "ingredient": if (a.AtcCode != null) { key = a.Substances.ToLower(); } break; case "regnr": if (a.Regnrs != null) { key = a.Regnrs.ToLower(); } break; case "application": if (a.Application != null) { key = a.Application.ToLower(); } break; case "eancode": if (a.Packages != null) { key = a.Packages.ToLower(); } break; default: break; } return(key.Contains(query)); }).ToList(); UpdateSearchResults(state); return(_foundArticles.Count); }