예제 #1
0
            public virtual bool Next()
            {
                if (moreInclude)
                {
                    // move to next include
                    moreInclude = includeSpans.Next();
                }

                while (moreInclude && moreExclude)
                {
                    if (includeSpans.Doc() > excludeSpans.Doc())
                    {
                        // skip exclude
                        moreExclude = excludeSpans.SkipTo(includeSpans.Doc());
                    }

                    while (moreExclude && includeSpans.Doc() == excludeSpans.Doc() && excludeSpans.End() <= includeSpans.Start())
                    {
                        moreExclude = excludeSpans.Next();                         // increment exclude
                    }

                    if (!moreExclude || includeSpans.Doc() != excludeSpans.Doc() || includeSpans.End() <= excludeSpans.Start())
                    {
                        break;                         // we found a match
                    }
                    moreInclude = includeSpans.Next(); // intersected: keep scanning
                }
                return(moreInclude);
            }
예제 #2
0
            public virtual bool SkipTo(int target)
            {
                if (!spans.SkipTo(target))
                {
                    return(false);
                }

                return((spans.End() <= Enclosing_Instance.end) || Next());
            }
        /// <summary>The subSpans are ordered in the same doc, so there is a possible match.
        /// Compute the slop while making the match as short as possible by advancing
        /// all subSpans except the last one in reverse order.
        /// </summary>
        private bool ShrinkToAfterShortestMatch()
        {
            matchStart = subSpans[subSpans.Length - 1].Start();
            matchEnd   = subSpans[subSpans.Length - 1].End();
            if (subSpans[subSpans.Length - 1].IsPayloadAvailable())
            {
                SupportClass.CollectionsSupport.AddAll(subSpans[subSpans.Length - 1].GetPayload(), matchPayload);
            }
            int matchSlop = 0;
            int lastStart = matchStart;
            int lastEnd   = matchEnd;

            for (int i = subSpans.Length - 2; i >= 0; i--)
            {
                PayloadSpans prevSpans = subSpans[i];

                if (subSpans[i].IsPayloadAvailable())
                {
                    matchPayload.InsertRange(0, subSpans[i].GetPayload());
                }

                int prevStart = prevSpans.Start();
                int prevEnd   = prevSpans.End();
                while (true)
                {
                    // Advance prevSpans until after (lastStart, lastEnd)
                    if (!prevSpans.Next())
                    {
                        inSameDoc = false;
                        more      = false;
                        break;                         // Check remaining subSpans for final match.
                    }
                    else if (matchDoc != prevSpans.Doc())
                    {
                        inSameDoc = false;             // The last subSpans is not advanced here.
                        break;                         // Check remaining subSpans for last match in this document.
                    }
                    else
                    {
                        int ppStart = prevSpans.Start();
                        int ppEnd   = prevSpans.End();                       // Cannot avoid invoking .end()
                        if (!DocSpansOrdered(ppStart, ppEnd, lastStart, lastEnd))
                        {
                            break;                             // Check remaining subSpans.
                        }
                        else
                        {
                            // prevSpans still before (lastStart, lastEnd)
                            prevStart = ppStart;
                            prevEnd   = ppEnd;
                        }
                    }
                }
                System.Diagnostics.Debug.Assert(prevStart <= matchStart);
                if (matchStart > prevEnd)
                {
                    // Only non overlapping spans add to slop.
                    matchSlop += (matchStart - prevEnd);
                }

                /* Do not break on (matchSlop > allowedSlop) here to make sure
                 * that subSpans[0] is advanced after the match, if any.
                 */
                matchStart = prevStart;
                lastStart  = prevStart;
                lastEnd    = prevEnd;
            }
            return(matchSlop <= allowedSlop);            // ordered and allowed slop
        }
 public virtual int End()
 {
     return(spans.End());
 }