IEnumerable <Hit> GetProximalHits(int proximity) { var proximalHits = new List <Hit>(); Hits = Hits.OrderByDescending(h => h.Index).ThenByDescending(h => h.Skip).ToList(); for (var i = 0; i < Hits.Count(); i++) { var current = Hits[i]; var j = i + 1 < Hits.Count() ? i + 1 : i; var next = Hits[j]; var currentIndex = current.Index; var nextIndex = next.Index; var currentSkip = current.Skip; var nextSkip = next.Skip; if (Math.Abs(currentSkip - nextSkip) <= proximity || Math.Abs(currentIndex - nextIndex) <= proximity) { if (!proximalHits.Contains(current)) { proximalHits.Add(current); } if (!proximalHits.Contains(next)) { proximalHits.Add(next); } } } Hits = Hits.OrderBy(h => h.Index).ThenBy(h => h.Skip).ToList(); return(proximalHits); }
public override string ToString() { return($@"Searching text starting at position {Start + 1} until position {Stop + 1} skipping every {FromSkip} to {ToSkip} letter(s) searching for {string.Join(",", Terms ?? new List<string>())} within a proximity of {Proximity} letter(s). {Hits.Count()} total hit(s) found: {string.Join("\n", Hits ?? new List<Hit>())} " ); }