示例#1
0
        private static SearchResult Search(HtmlPage page, string searchTerm)
        {
            int matches    = 0;
            var searchTime = Stopwatch.StartNew();

            foreach (string line in page.HTML)
            {
                if (line.Contains(searchTerm))
                {
                    matches++;
                }
            }

            searchTime.Stop();

            return(new SearchResult(page.URL, page.Title, matches, searchTerm, searchTime.Elapsed.TotalMilliseconds));
        }
示例#2
0
        private static SearchResult SearchParallel(HtmlPage page, string searchTerm)
        {
            int matches = 0;
            var sw      = Stopwatch.StartNew();

            Parallel.ForEach(page.HTML, line => {
                Parallel.ForEach(line.Split(' '), word => {
                    if (word.ToLower().Contains(searchTerm) || word.ToLower().Equals(searchTerm.ToLower()))
                    {
                        matches++;
                    }
                });
            });

            sw.Stop();

            return(new SearchResult(page.URL, page.Title, matches, searchTerm, sw.Elapsed.TotalMilliseconds));
        }