Example #1
0
        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);
        }
Example #2
0
        string OffsetHitsToGrid(List <Hit> hits)
        {
            Hits = Hits.OrderBy(h => h.Index).ThenBy(h => h.Skip).ToList();
            var low = Hits.FirstOrDefault().Index;

            var last = Hits.LastOrDefault();
            var high = last.Index;

            high += (last.Term?.Length ?? 1) * last.Skip;

            Hits = Hits.Select(h => new Hit(h.Term, (h.Index - low), h.Start, h.Skip)).ToList();
            low  = low - Start >= 0 ? low - Start : low;
            high = high >= Text.Length ? Text.Length - 1 : high;
            return(Range(Text, low, high));
        }