Esempio n. 1
0
        public SearchResultListItem2(SearchResult2 result)
        {
            _result = result;

            this.Orientation = Orientation.Vertical;
            this.Margin = new Thickness(0, 0, 0, 20);

            TextBlock TitleBlock = new TextBlock()
            {
                Text = _result.SourceTitle,
                FontSize = 42,
                FontFamily = new FontFamily("Segoe WP SemiLight"),
                Margin = new Thickness(0, 0, 0, 0)
            };
            this.Children.Add(TitleBlock);

            TextBlock TextBlock = new TextBlock();
            TextBlock.Margin = new Thickness(0, 0, 0, 0);
            if (_result.HasTextMatches)
            {
                foreach (Inline i in GetInlines())
                    TextBlock.Inlines.Add(i);
            }
            else
            {
                TextBlock.Text = _result.SourceText;
            }
            this.Children.Add(TextBlock);
        }
Esempio n. 2
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;
        }