public void Search() { List <ResultRow> resultMatch = new List <ResultRow>(); List <ResultRow> results = new List <ResultRow>(); foreach (Model.Story story in stories.getStories()) { foreach (Model.Chapter chap in story.getChapters()) { MyRegex regex = new MyRegex(); regex.InputString = input; regex.Content = chap.content; Match match = regex.GenerateRegexAllMatch(); if (match != null) { int start = match.Index; int len = match.Value.Length; ResultRow item = new ResultRow(); item.index_story = story.idt - 1; item.index_chap = story.getChapters().IndexOf(chap); item.start = start; item.len = len; item.resulttext = story.name + " - " + chap.name + ": " + match.Value; resultMatch.Add(item); } else { List <Result> result = regex.FuzzyMethod(); foreach (Result rs in result) { int start = rs.begin; int len = rs.end - rs.begin; ResultRow item = new ResultRow(); item.index_story = story.idt - 1; item.index_chap = story.getChapters().IndexOf(chap); item.start = start; item.len = len; item.resulttext = story.name + " - " + chap.name + ": (" + rs.numberRhythmsMatch + ")" + chap.content.Substring(start, len); results.Add(item); } } } } listBox1.Invoke((MethodInvoker) delegate() { listBox1.DataSource = resultMatch.Count > 0 ? resultMatch : results; }); progress.Invoke((MethodInvoker) delegate() { progress.Dispose(); }); }
private void HomePage_Load(object sender, EventArgs e) { resize(); Model.Stories stories = Model.MyDatabase.getStories(); List <Model.Story> list = stories.getStories(); liststory.DataSource = list; MyRegex regex = new MyRegex(); regex.InputString = "Phong Điền Khí"; regex.Content = "tiền bối Phong Thanh ... gã khi Điền Bá .. bên tông phái"; Match match = regex.GenerateRegexAllMatch(); if (match != null) { MessageBox.Show(match.Value); } else { List <Result> results = regex.FuzzyMethod(); } }
public void Search() { List <string> results = new List <string>(); Model.Stories stories = Model.MyDatabase.getStories(); foreach (Model.Story story in stories.getStories()) { foreach (Model.Chapter chap in story.getChapters()) { MyRegex regex = new MyRegex(); regex.InputString = input; regex.Content = chap.content; Match match = regex.GenerateRegexAllMatch(); if (match != null) { MessageBox.Show("Tìm thấy tại " + story.name + " - " + chap.name); this.Dispose(); return; } else { List <Result> result = regex.FuzzyMethod(); foreach (Result rs in result) { int start = rs.begin; int len = rs.end - rs.begin; results.Add(story.name + " - " + chap.name + ": (" + rs.numberRhythmsMatch + ")" + chap.content.Substring(start, len)); } } } } listBox1.DataSource = results; this.Show(); }