本文整理汇总了C#中SearchResult.SetTextMatches方法的典型用法代码示例。如果您正苦于以下问题:C# SearchResult.SetTextMatches方法的具体用法?C# SearchResult.SetTextMatches怎么用?C# SearchResult.SetTextMatches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchResult
的用法示例。
在下文中一共展示了SearchResult.SetTextMatches方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
private void Search(object sender, DoWorkEventArgs e)
{
string pattern = (string)e.Argument;
string lastPattern;
List<SearchResult> results = new List<SearchResult>();
List<Document> resultScope = new List<Document>();
if (pattern.Equals(string.Empty))
{
e.Result = SetResultArgs(pattern, results);
return;
}
else if (_pastResults.ContainsKey(pattern))
{
e.Result = SetResultArgs(pattern, _pastResults[pattern].SearchResults);
return;
}
else if (TryGetLastPattern(pattern, out lastPattern))
{
SetScope(_pastResults[lastPattern].ResultScope);
}
// Search
Regex rgx = new Regex(Regex.Escape(pattern), RegexOptions.IgnoreCase);
foreach (Document doc in _scope)
{
SearchResult result = new SearchResult(doc, pattern);
string title = doc.DisplayName;
MatchCollection titleMatches = rgx.Matches(title);
result.SetTitleMatches(title, titleMatches);
if (SettingUtils.GetSetting<bool>(Setting.SearchFileText))
{
string text = WhitespaceRgx.Replace(doc.Text, " ");
MatchCollection textMatches = rgx.Matches(text);
result.SetTextMatches(text, textMatches);
}
if (result.HasMatches)
{
results.Add(result);
resultScope.Add(doc);
}
}
Triple t = new Triple(resultScope, results);
_pastResults.Add(pattern, t);
e.Result = SetResultArgs(pattern, results);
}