/// <summary> /// Gets an enumerator /// </summary> public IEnumerator <Hit> GetEnumerator() { int curPos = startPosition; Hit find; while (curPos < text.Length) { find = GetMatch(curPos); if (find.Start > -1) { bool isMatch = true; foreach (IMatchFilter filter in matchFilters) { isMatch &= filter.IsMatch(searchQuery.QueryText, text, find); } curPos = find.Start + 1; if (!isMatch) { continue; //try again } else { Hit translatedHit = find; for (int h = bodyIgnoreHandlers.Count - 1; h >= 0; h--)//we want to translate back in the opposite order than the text was translated in. { translatedHit = bodyIgnoreHandlers[h].TranslateHit(translatedHit); } yield return(translatedHit); } } else { break; } } }
public bool IsMatch(string searchQuery, string text, Hit hit) { bool startBoundaryOK = _part == Part.Suffix || (hit.Start == 0 || !Char.IsLetterOrDigit(text[hit.Start - 1])); bool endBoundaryOK = _part == Part.Prefix || ((hit.Start + searchQuery.Length >= text.Length) || !Char.IsLetterOrDigit(text[hit.Start + hit.Length])); return startBoundaryOK && endBoundaryOK; }
/// <summary> /// /// </summary> /// <param name="hit"></param> /// <returns></returns> public Hit TranslateHit(Hit hit) { int translatedStart = TranslateIndex(hit.Start, true); int translatedEnd = TranslateIndex(hit.Start + hit.Length, false); if (translatedEnd < translatedStart) translatedEnd = translatedStart;//this can happen when the search string is empty and theres a whitespace that was ignored return new Hit(translatedStart, translatedEnd - translatedStart); }