// This behavior is case sensitive public override IEnumerable<object> FindMatchingItems(string searchText, IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var strings = searchText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (strings.Length == 0) { return base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode); } string name = string.Empty; string capital = string.Empty; if (strings.Length > 0) { name = strings[0]; } if (strings.Length > 1) { capital = strings[1].TrimStart(' '); } IEnumerable<object> results = null; if (textSearchMode == TextSearchMode.Contains) { results = items.OfType<Country>().Where(x => x.Name.Contains(name) && x.Capital.Contains(capital)); } else { results = items.OfType<Country>().Where(x => x.Name.StartsWith(name) && x.Capital.StartsWith(capital)); } return results.Where(x => !escapedItems.Contains(x)); }
public override IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { if(searchText.Length >= 5) { return base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode); } return Enumerable.Empty<object>(); }
public override IEnumerable<object> FindMatchingItems(string searchText, IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var result = base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode) as IEnumerable<object>; if (string.IsNullOrEmpty(searchText) || !result.Any()) { return ((IEnumerable<object>)items).Where(x => !escapedItems.Contains(x)); } return result; }
public void Initialize() { MemberList = new List<MemberListViewItemModel>(); //ResultList = new List<MemberListViewItemModel>(); AccessToken = ApplicationResource.DefaultAccessToken; _searchMode = TextSearchMode.Filename_only; SearchModeList = new List<string>(); foreach (TextSearchMode mode in Enum.GetValues(typeof(TextSearchMode))) { SearchModeList.Add(mode.ToString().Replace("_", " ")); } SearchResultsLimit = ApplicationResource.SearchDefaultLimit; }
public override IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { if (string.IsNullOrWhiteSpace(searchText)) { return items.OfType<object>().Where(x => !escapedItems.Contains(x)); } else { return base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode); } }
public override IEnumerable<object> FindMatchingItems(string searchText, IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var matches = base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode); if (matches.Count() == 0 && !string.IsNullOrEmpty(searchText)) { return (List<object>)items; } return base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode); }
public void Initialize() { MemberList = new List <MemberListViewItemModel>(); //ResultList = new List<MemberListViewItemModel>(); AccessToken = ApplicationResource.DefaultAccessToken; _searchMode = TextSearchMode.Filename_only; SearchModeList = new List <string>(); foreach (TextSearchMode mode in Enum.GetValues(typeof(TextSearchMode))) { SearchModeList.Add(mode.ToString().Replace("_", " ")); } SearchResultsLimit = ApplicationResource.SearchDefaultLimit; }
/// <summary> /// Lance une recherche /// </summary> public IEnumerable <object> FindMatchingItems( string searchText, System.Collections.IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { if (items == null) { return(Enumerable.Empty <object>()); } if (escapedItems == null) { throw new ArgumentNullException(nameof(escapedItems)); } if (string.IsNullOrWhiteSpace(searchText)) { Task.Factory.StartNew( () => { if (this.ItemsFound != null) { var itemsFound = items.OfType <object>().Where(x => !escapedItems.Contains(x)); if (this.ItemsFound != null) { this.ItemsFound(null, new AsyncItemSearchEventArgs(itemsFound)); } } }, CancellationToken.None, TaskCreationOptions.AttachedToParent, TaskScheduler.FromCurrentSynchronizationContext()); return(Enumerable.Empty <object>()); } else { return(filter.FindMatchingItems( searchText, items, escapedItems, textSearchPath, textSearchMode)); } }
public override System.Collections.Generic.IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, System.Collections.Generic.IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var dependencies = new List<Dependency>(); var toRemove = escapedItems.OfType<Dependency>(); for (int i = 0; i < items.Count; i++) { dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.FinishFinish }); dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.FinishStart }); dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.StartFinish }); dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.StartStart }); } var searchTexts = searchText.Split(new char[] { '-' }); var titleToUpper = searchTexts.First().Trim().ToUpper(); var typeToUpper = searchTexts.Length > 1 ? searchTexts[1].Trim().ToUpper() : string.Empty; var result = dependencies.Where(x => !toRemove.Any(y => y.FromTask == x.FromTask && y.Type == x.Type)); result = result.Where(x => x.FromTask.Title.ToUpper().StartsWith(titleToUpper.ToUpper()) && x.Type.ToString().ToUpper().StartsWith(typeToUpper)); return result; }
public override int FindHighlightedIndex(string searchText, System.Collections.IList filteredItems, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var items = filteredItems.OfType<Item>().ToList<Item>(); if (items != null) { if (items.Any(x => x.Name == searchText)) { // there is an exact match var matchedItem = items.First(x => x.Name == searchText); // return the index of the matched item return items.IndexOf(matchedItem); } } // there isn't exact match // return the index of the last item from the filtered items return items.Count - 1; }
/// <summary> /// Creates a Func that compares the provided text with its parameter. The result depends on the TextSearchMode. /// </summary> public static Func <string, bool> CreatePartialMatchFunc(string text, TextSearchMode mode) { if (mode.IsContains()) { if (mode.IsCaseSensitive()) { return((string itemText) => itemText.Contains(text)); } else { return((string itemText) => itemText.IndexOf(text, StringComparison.OrdinalIgnoreCase) > -1); } } else if (mode.IsStartsWith()) { var stringComparison = mode.IsCaseSensitive() ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; return((string itemText) => itemText.StartsWith(text, stringComparison)); } return(null); }
public override IEnumerable <object> FindMatchingItems(string searchText, IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { if (string.IsNullOrWhiteSpace(searchText)) { return((IEnumerable <object>)items);//.Where(x => !escapedItems.Contains(x)); } return(base.FindMatchingItems(searchText, items, new object[0], textSearchPath, textSearchMode) as IEnumerable <object>); }
public override IEnumerable <object> FindMatchingItems(string searchText, IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var stations = items.Cast <Station>().ToArray(); var searchTextUpper = searchText.ToUpper(); var codeResults = new List <Station>(); var nameResults = new List <Station>(); var pinyinResults = new List <Station>(); var results = new List <Station>(); switch (textSearchMode) { case TextSearchMode.StartsWith: case TextSearchMode.StartsWithCaseSensitive: foreach (var station in stations) { if (station.Code == searchTextUpper) { codeResults.Add(station); } else if (station.Name.StartsWith(searchTextUpper)) { nameResults.Add(station); } else if (station.PinyinInitials.StartsWith(searchTextUpper)) { pinyinResults.Add(station); } } break; case TextSearchMode.Contains: case TextSearchMode.ContainsCaseSensitive: foreach (var station in stations) { if (station.Code == searchTextUpper) { codeResults.Add(station); } else if (station.Name.Contains(searchTextUpper)) { nameResults.Add(station); } else if (station.PinyinInitials.Contains(searchTextUpper)) { pinyinResults.Add(station); } } break; } results.AddRange(codeResults); results.AddRange(nameResults); results.AddRange(pinyinResults); return(results); }
/// <summary> /// Creates a Func that compares the provided text with its parameter. The result depends on the TextSearchMode. /// </summary> public static Func <string, bool> CreateFullMatchFunc(string text, TextSearchMode mode) { var stringComparison = mode.IsCaseSensitive() ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; return((string itemText) => itemText.Equals(text, stringComparison)); }
public override IEnumerable <object> FindMatchingItems(string searchText, IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var matches = base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode); if (matches.Count() == 0 && !string.IsNullOrEmpty(searchText)) { return((List <object>)items); } return(base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode)); }
public override IEnumerable <object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { if (searchText.Length >= 5) { return(base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode)); } return(Enumerable.Empty <object>()); }
public override IEnumerable <object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { try { var lastText = searchText.Split(',').LastOrDefault(); var matches = base.FindMatchingItems(lastText, items, escapedItems, textSearchPath, textSearchMode); if (string.IsNullOrWhiteSpace(lastText)) { return(items.OfType <object>().Where(x => !escapedItems.Contains(x))); } return(matches); } catch (Exception ex) { Log.This(ex); return(null); } }
public override System.Collections.Generic.IEnumerable <object> FindMatchingItems(string searchText, System.Collections.IList items, System.Collections.Generic.IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var dependencies = new List <Dependency>(); var toRemove = escapedItems.OfType <Dependency>(); for (int i = 0; i < items.Count; i++) { dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.FinishFinish }); dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.FinishStart }); dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.StartFinish }); dependencies.Add(new Dependency() { FromTask = items[i] as GanttTask, Type = DependencyType.StartStart }); } var searchTexts = searchText.Split(new char[] { '-' }); var titleToUpper = searchTexts.First().Trim().ToUpper(); var typeToUpper = searchTexts.Length > 1 ? searchTexts[1].Trim().ToUpper() : string.Empty; var result = dependencies.Where(x => !toRemove.Any(y => y.FromTask == x.FromTask && y.Type == x.Type)); result = result.Where(x => x.FromTask.Title.ToUpper().StartsWith(titleToUpper.ToUpper()) && x.Type.ToString().ToUpper().StartsWith(typeToUpper)); return(result); }
public override IEnumerable <object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { if (string.IsNullOrWhiteSpace(searchText)) { return(items.OfType <object>().Where(x => !escapedItems.Contains(x))); } else { return(base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode)); } }
/// <summary> /// Initiate class with settings. /// </summary> /// <param name="mode"></param> /// <param name="value"></param> public TextSearch(TextSearchMode mode, string value) { Mode = mode; Value = value; }
public static bool IsStartsWith(this TextSearchMode mode) { return(mode == TextSearchMode.StartsWith || mode == TextSearchMode.StartsWithCaseSensitive); }
public static bool IsCaseSensitive(this TextSearchMode mode) { return(mode == TextSearchMode.ContainsCaseSensitive || mode == TextSearchMode.StartsWithCaseSensitive); }
public override int FindHighlightedIndex(string searchText, System.Collections.IList filteredItems, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var items = filteredItems.OfType <Dish>().ToList <Dish>(); if (items != null) { if (items.Any(x => x.Name == searchText)) { // there is an exact match var matchedItem = items.First(x => x.Name == searchText); // return the index of the matched item return(items.IndexOf(matchedItem)); } } // there isn't exact match // return the index of the last item from the filtered items return(items.Count - 1); }
internal static int FindMatchingItems(ItemsControl itemsControl, string text, TextSearchMode mode, int startIndex, out List <int> matchIndexes) { matchIndexes = new List <int>(); ItemCollection items = itemsControl.Items; if (items.Count == 0) { return(-1); } bool isEmptyText = string.IsNullOrEmpty(text); Func <string, bool> isFullMatch; Func <string, bool> isPartialMatch; if (isEmptyText) { isPartialMatch = isFullMatch = (string itemText) => false; } else { isFullMatch = CreateFullMatchFunc(text, mode); isPartialMatch = CreatePartialMatchFunc(text, mode) ?? isFullMatch; } Func <object, object> getTextFunc = null; int fullMatchIndex = -1; for (int i = startIndex; i < items.Count; i++) { object item = items[i]; if (getTextFunc == null && item != null) { getTextFunc = BindingExpressionHelper.CreateGetValueFunc(item.GetType(), GetPrimaryTextPath(itemsControl)); } var container = itemsControl.ItemContainerGenerator.ContainerFromIndex(i) as Control; if (container != null && !container.IsEnabled) { continue; } string primaryText = GetPrimaryText(item, getTextFunc); if (fullMatchIndex < 0 && isFullMatch(primaryText)) { fullMatchIndex = i; matchIndexes.Insert(0, fullMatchIndex); } else if (isPartialMatch(primaryText)) { matchIndexes.Add(i); } } return(fullMatchIndex); }
public static bool IsContains(this TextSearchMode mode) { return(mode == TextSearchMode.Contains || mode == TextSearchMode.ContainsCaseSensitive); }
// This behavior is case sensitive public override IEnumerable <object> FindMatchingItems(string searchText, IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var strings = searchText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (strings.Length == 0) { return(base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode)); } string name = string.Empty; string capital = string.Empty; if (strings.Length > 0) { name = strings[0].TrimEnd(' '); } if (strings.Length > 1) { capital = strings[1].TrimStart(' '); } IEnumerable <object> results = null; name = name.ToLower(); capital = capital.ToLower(); if (textSearchMode == TextSearchMode.Contains) { results = items.OfType <Country>().Where(x => x.Name.Contains(name) && x.Capital.Contains(capital)); } else { results = items.OfType <Country>().Where(x => x.Name.ToLower().StartsWith(name) && x.Capital.ToLower().StartsWith(capital)); } return(results.Where(x => !escapedItems.Contains(x))); }
/* public string RemoveDiacritics(string text) => string.Concat(text.Normalize(NormalizationForm.FormD) * .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark)) * .Normalize(NormalizationForm.FormC);*/ // giữ cho chắc :v cấm delete nha /* public override IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) * { * searchText = this.RemoveDiacritics(searchText.ToUpper()); * * // Create key-value pair for each item in the itemsSource (you can cache this collection if it is not changed dynamically * // Use the key-value pair later when you have to return the original item. * var modifiedItems = new Dictionary<object, string>(); * if (textSearchPath != null && textSearchPath != string.Empty) * { * foreach (object originalItem in items) * { * var modifiedItem = this.ModifyItem(originalItem, textSearchPath); * modifiedItems.Add(originalItem, modifiedItem); * } * } * else * { * foreach (object originalItem in items) * { * var modifiedItem = this.RemoveDiacritics(originalItem.ToString().ToUpper()); * modifiedItems.Add(originalItem, modifiedItem); * } * } * * // Get the matching items by sending the itemsSource without diacritics * var matchingItems = base.FindMatchingItems(searchText, modifiedItems.Values.ToList(), escapedItems, string.Empty, textSearchMode); * * // return all Original matching items * var originalMatchingItems = new List<object>(); * foreach (string matchItem in matchingItems) * { * var dictionaryItem = modifiedItems.FirstOrDefault(p => p.Value == matchItem); * modifiedItems.Remove(dictionaryItem.Key); * originalMatchingItems.Add(dictionaryItem.Key); * } * * if (string.IsNullOrEmpty(searchText) || !originalMatchingItems.Any()) * { * return ((IEnumerable<object>)items).Where(x => !escapedItems.Contains(x)); * } * * return originalMatchingItems; * } */ public override IEnumerable <object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { if (string.IsNullOrEmpty(searchText) || string.IsNullOrEmpty(searchText.Trim())) { return(((IEnumerable <object>)items).Where(x => !escapedItems.Contains(x))); } var resultItems = new List <object>(); searchText = Dish.RemoveDiacritics(searchText); string queryStr = Dish.CreateQueryLinQ(searchText, "item"); // Create key-value pair for each item in the itemsSource (you can cache this collection if it is not changed dynamically // Use the key-value pair later when you have to return the original item. var modifiedItems = new Dictionary <object, string>(); if (textSearchPath != null && textSearchPath != string.Empty) { foreach (var(originalItem, modifiedItem) in from object originalItem in items let modifiedItem = this.ModifyItem(originalItem, textSearchPath) select(originalItem, modifiedItem)) { modifiedItems.Add(originalItem, modifiedItem); } } else { foreach (var(originalItem, modifiedItem) in from object originalItem in items let modifiedItem = Dish.RemoveDiacritics(originalItem.ToString().ToUpper()) select(originalItem, modifiedItem)) { modifiedItems.Add(originalItem, modifiedItem); } } List <string> matchItems = new List <string>(); if (Dish.checkQuery(queryStr)) { matchItems = modifiedItems.Values.ToList().WhereDynamic(item => queryStr).ToList(); } foreach (var dictionaryItem in from string matchItem in matchItems let dictionaryItem = modifiedItems.FirstOrDefault(p => p.Value == matchItem) select dictionaryItem) { modifiedItems.Remove(dictionaryItem.Key); resultItems.Add(dictionaryItem.Key); } return(resultItems); }
public override IEnumerable<object> FindMatchingItems(string searchText, IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { logger.Trace("Search text : {0}", searchText); Regex rgx = new Regex("[^a-z0-9]"); String searchStrip = rgx.Replace(searchText.ToLower().Normalize(NormalizationForm.FormD), ""); //chuyen thanh chu, so, bo dau cach... List<object> returnList = new List<object>(); foreach (Inventory_Product ip in items) { String productNameStrip = rgx.Replace(ip.Product.Name.ToLower().Normalize(NormalizationForm.FormD), ""); if (productNameStrip.Contains(searchText) || ip.Product.ProductCode.Contains(searchText) ) { returnList.Add(ip); logger.Trace("True : {0}", ip.Product.Name.ToLower()); } else logger.Trace("False : {0}", ip.Product.Name.ToLower()); } //var result = base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode) as IEnumerable<object>; //if (string.IsNullOrEmpty(searchText) || !returnList.Any()) //{ // return ((IEnumerable<object>)items).Where(x => !escapedItems.Contains(x)); //} return (IEnumerable<object>)returnList; }
public override IEnumerable <object> FindMatchingItems(string searchText, IList items, IEnumerable <object> escapedItems, string textSearchPath, TextSearchMode textSearchMode) { var result = base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode) as IEnumerable <object>; if (string.IsNullOrEmpty(searchText) || !result.Any()) { return(((IEnumerable <object>)items).Where(x => !escapedItems.Contains(x))); } return(result); }