/// <summary> /// Scans a queue of runs and highlights matches. /// </summary> /// <param name="runQueue">Run queue</param> /// <param name="query">Query</param> /// <param name="addHighlightDelegate">Delegate to call when a hit is found</param> public virtual void ScanQueuedRuns(RunQueue runQueue, Query query, AddHighlight addHighlightDelegate) { //this.searchText = query; System.Text.StringBuilder queuedText = new System.Text.StringBuilder(100); queuedText.Length = 0; for (int i = 0; i < runQueue.Count && (i <= 1 || queuedText.Length < 100); i++)//look at the text in queue up until 100 chars of the 2nd run { queuedText.Append(runQueue[i].HitAvailableText); } int currentIndex = 0; string text = queuedText.ToString(); int index; Hit hit; TextMatchers textMatchers = query.GetTextMatchers(text, FindOptions); while ((hit = GetNextMatch(textMatchers, currentIndex)).Start > -1 && currentGlobalScanHighlightCount < maximumHitsToHighlight)//find a hit for searchText in the plain text version. { index = hit.Start; //we have a hit, we need to find the runs it was in and highlight int highlightStart; int gobbledChars = 0; int runHitLength = hit.Length; int highlightLength; //string searchSegment = query.QueryText; bool moreToFind = true; while (moreToFind) { Run runAtPos = runQueue.HitPosition(index, runHitLength, out highlightStart, out gobbledChars); //gobbledChars is the number of chars in runAtPos that were used (this could be the entire run length if the runHitLength is less than the //number of chars in the run). //indexOffset is where in the run to start highlighting if (gobbledChars < runHitLength) { moreToFind = true; //there weren't enough chars in the run, so we'll need to look for more index += gobbledChars; runHitLength -= gobbledChars; highlightLength = gobbledChars; } else { moreToFind = false; highlightLength = runHitLength; } addHighlightDelegate(runAtPos, highlightStart, highlightLength); currentGlobalScanHighlightCount++; currentIndex = index + runHitLength; } } }
/// <summary> /// /// </summary> /// <param name="searchText"></param> /// <param name="currentIndex"></param> /// <param name="text"></param> /// <returns></returns> public Hit GetNextMatch_FOR_TESTING(string searchText, int currentIndex, string text) { Query q = new Query(searchText); return(GetNextMatch(q.GetTextMatchers(text, FindOptions), currentIndex)); }
/// <summary> /// /// </summary> /// <param name="searchText"></param> /// <param name="currentIndex"></param> /// <param name="text"></param> /// <returns></returns> public Hit GetNextMatch_FOR_TESTING(string searchText, int currentIndex, string text) { Query q = new Query(searchText); return GetNextMatch(q.GetTextMatchers(text, FindOptions), currentIndex); }
/// <summary> /// Scans a queue of runs and highlights matches. /// </summary> /// <param name="runQueue">Run queue</param> /// <param name="query">Query</param> /// <param name="addHighlightDelegate">Delegate to call when a hit is found</param> public virtual void ScanQueuedRuns(RunQueue runQueue, Query query, AddHighlight addHighlightDelegate) { //this.searchText = query; System.Text.StringBuilder queuedText = new System.Text.StringBuilder(100); queuedText.Length = 0; for (int i = 0; i < runQueue.Count && (i <= 1 || queuedText.Length < 100); i++)//look at the text in queue up until 100 chars of the 2nd run { queuedText.Append(runQueue[i].HitAvailableText); } int currentIndex = 0; string text = queuedText.ToString(); int index; Hit hit; TextMatchers textMatchers = query.GetTextMatchers(text, FindOptions); while ((hit = GetNextMatch(textMatchers, currentIndex)).Start > -1 && currentGlobalScanHighlightCount < maximumHitsToHighlight)//find a hit for searchText in the plain text version. { index = hit.Start; //we have a hit, we need to find the runs it was in and highlight int highlightStart; int gobbledChars = 0; int runHitLength = hit.Length; int highlightLength; //string searchSegment = query.QueryText; bool moreToFind = true; while (moreToFind) { Run runAtPos = runQueue.HitPosition(index, runHitLength, out highlightStart, out gobbledChars); //gobbledChars is the number of chars in runAtPos that were used (this could be the entire run length if the runHitLength is less than the //number of chars in the run). //indexOffset is where in the run to start highlighting if (gobbledChars < runHitLength) { moreToFind = true; //there weren't enough chars in the run, so we'll need to look for more index += gobbledChars; runHitLength -= gobbledChars; highlightLength = gobbledChars; } else { moreToFind = false; highlightLength = runHitLength; } addHighlightDelegate(runAtPos, highlightStart, highlightLength); currentGlobalScanHighlightCount++; currentIndex = index + runHitLength; } } }