private void SetChildSources(List <KeyValuePair <string, object> > source) { var visitedItems = new Dictionary <string, int>(); foreach (var vp in source) { if (!Objects.Contains(vp.Value)) { Objects.Add(vp.Value); } if (string.IsNullOrEmpty(vp.Key) || string.IsNullOrWhiteSpace(vp.Key) || visitedItems.ContainsKey(vp.Key)) { continue; } else { char key = CharTool.ToLowerFast(vp.Key[0]); Node node = Create(key); // Düğüm oluştur. var subNodeSource = this.CreateSubNodeSource(source, key, visitedItems); if (subNodeSource.Count > 0) { node.SetChildSources(subNodeSource); } this.Children.Add(node); } } }
public Node GetChildNode(char c) { var invar = CharTool.ToLowerFast(c); var child = this.Children.FirstOrDefault(x => CharTool.ToLowerFast(x.NodeKey) == invar); return(child); }
public override bool Equals(object obj) { if (!(obj is Node)) { return(false); } char c1 = CharTool.ToLowerFast((obj as Node).NodeKey); char c2 = CharTool.ToLowerFast(this.NodeKey); return(c1 == c2); }
private List <KeyValuePair <string, object> > CreateSubNodeSource(List <KeyValuePair <string, object> > mainSource, char key, Dictionary <string, int> visitedItems) { List <KeyValuePair <string, object> > subNodeSource = new List <KeyValuePair <string, object> >(); foreach (var vp in mainSource) { if (!string.IsNullOrEmpty(vp.Key)) { if (CharTool.ToLowerFast(vp.Key[0]) == key) { var item = new KeyValuePair <string, object>(vp.Key.Substring(1, vp.Key.Length - 1), vp.Value); subNodeSource.Add(item); if (!visitedItems.ContainsKey(vp.Key)) { visitedItems.Add(vp.Key, 1); } } } } return(subNodeSource); }
public void AddNewItem(string path, object item) { if (string.IsNullOrEmpty(path) || string.IsNullOrWhiteSpace(path)) { return; } char keyChar = CharTool.ToLowerFast(path[0]); if (!this.Children.Any(x => x.NodeKey == keyChar)) { // Düğüm oluştur. if (!this.Objects.Contains(item)) { this.Objects.Add(item); } var child = CreateWithSource(keyChar, new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>(path.Substring(1, path.Length - 1), item) }); this.Children.Add(child); } else { // Düğüm zaten oluşturulmuş. Node child = this.GetChildNode(keyChar); if (!child.Objects.Contains(item)) { child.Objects.Add(item); } child.AddNewItem(path.Substring(1, path.Length - 1), item); } }
public HashSet <object> Search(string searchKey, ResultCompiling resultCompiling, CombineMode combineMode = CombineMode.Intersection) { /* * if (!this.IsReady) * return new HashSet<object>(); */ this.SpellFixList.Clear(); if (string.IsNullOrEmpty(searchKey.Trim(' '))) { return(this.DataSource); } if (this.Tree != null) { if (resultCompiling == ResultCompiling.Basic) { Node node = this.Tree.FindNode(searchKey); if (node != null) { return(node.Objects); } else { var unaccentedText = String.Join("", searchKey.Normalize(NormalizationForm.FormD).Where(c => CharTool.ToLowerFast(c) != c)); var node2 = this.Tree.FindNode(unaccentedText); if (node2 != null) { return(node2.Objects); } else { return(this.GetSpellCheckerSuggestions(searchKey)); } } } else { List <string> searchKeys = searchKey.Split(' ').Select(tag => tag.Trim()).Where(tag => !string.IsNullOrEmpty(tag)).ToList(); if (searchKeys.Count == 1) { var trimmedSearchKey = searchKey.Trim(); Node node = this.Tree.FindNode(trimmedSearchKey); if (node != null) { return(node.Objects); } else { var unaccentedText = ConvertTurkishCharsToEnglish(trimmedSearchKey); var node2 = this.Tree.FindNode(unaccentedText); if (node2 != null) { return(node2.Objects); } else { return(this.GetSpellCheckerSuggestions(trimmedSearchKey)); } } } List <Node> nodeList = new List <Node>(); foreach (string key in searchKeys) { Node found = this.Tree.FindNode(key); if (found != null) { nodeList.Add(found); } } if (nodeList.Count > 0) { return(this.CombineResults(nodeList, combineMode)); } else { return(this.GetSpellCheckerSuggestions(searchKeys.First())); } } } else { return(new HashSet <object>()); } }