Esempio n. 1
0
        private void Search(object sender, DoWorkEventArgs e)
        {
            _isSearching = true;
            string pattern = (string)e.Argument;
            List<SearchResult2> results = new List<SearchResult2>();

            // Search
            Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
            foreach (Document doc in _scope)
            {
                SearchResult2 result = new SearchResult2(doc, pattern);

                string title = doc.DisplayName;
                MatchCollection titleMatches = rgx.Matches(title);
                result.SetTitleMatches(title, titleMatches);

                string text = WhitespaceRgx.Replace(doc.Text, " ");
                MatchCollection textMatches = rgx.Matches(text);
                result.SetTextMatches(text, textMatches);

                if (result.HasMatches)
                    results.Add(result);
            }

            object[] args = new object[] { pattern, results };
            e.Result = args;
        }