예제 #1
0
            public override 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 override bool Next()
 {
     while (spans.Next())
     {
         // scan to next match
         if (End() <= Enclosing_Instance.end)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
 private bool InitSpanQueue(int target)
 {
     queue = new SpanQueue(enclosingInstance, Enclosing_Instance.clauses.Count);
     System.Collections.IEnumerator i = Enclosing_Instance.clauses.GetEnumerator();
     while (i.MoveNext())
     {
         Spans spans = ((SpanQuery)i.Current).GetSpans(reader);
         if (((target == -1) && spans.Next()) || ((target != -1) && spans.SkipTo(target)))
         {
             queue.Put(spans);
         }
     }
     return(queue.Size() != 0);
 }
예제 #4
0
 public /*protected internal*/ virtual bool SetFreqCurrentDoc()
 {
     if (!more)
     {
         return(false);
     }
     doc  = spans.Doc();
     freq = 0.0f;
     do
     {
         int matchLength = spans.End() - spans.Start();
         freq += GetSimilarity().SloppyFreq(matchLength);
         more  = spans.Next();
     }while (more && (doc == spans.Doc()));
     return(true);
 }
예제 #5
0
        /// <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();
            System.Collections.Generic.Dictionary <byte[], byte[]> possibleMatchPayloads = new System.Collections.Generic.Dictionary <byte[], byte[]>();
            if (subSpans[subSpans.Length - 1].IsPayloadAvailable())
            {
                System.Collections.Generic.ICollection <byte[]> payload = subSpans[subSpans.Length - 1].GetPayload();
                foreach (byte[] pl in payload)
                {
                    if (!possibleMatchPayloads.ContainsKey(pl))
                    {
                        possibleMatchPayloads.Add(pl, pl);
                    }
                }
            }

            System.Collections.Generic.List <byte[]> possiblePayload = null;

            int matchSlop = 0;
            int lastStart = matchStart;
            int lastEnd   = matchEnd;

            for (int i = subSpans.Length - 2; i >= 0; i--)
            {
                Spans prevSpans = subSpans[i];
                if (collectPayloads && prevSpans.IsPayloadAvailable())
                {
                    System.Collections.Generic.ICollection <byte[]> payload = prevSpans.GetPayload();
                    possiblePayload = new System.Collections.Generic.List <byte[]>(payload.Count);
                    possiblePayload.AddRange(payload);
                }

                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;
                            if (collectPayloads && prevSpans.IsPayloadAvailable())
                            {
                                System.Collections.Generic.ICollection <byte[]> payload = prevSpans.GetPayload();
                                possiblePayload = new System.Collections.Generic.List <byte[]>(payload.Count);
                                possiblePayload.AddRange(payload);
                            }
                        }
                    }
                }

                if (collectPayloads && possiblePayload != null)
                {
                    foreach (byte[] pl in possiblePayload)
                    {
                        if (!possibleMatchPayloads.ContainsKey(pl))
                        {
                            possibleMatchPayloads.Add(pl, pl);
                        }
                    }
                }

                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;
            }

            bool match = matchSlop <= allowedSlop;

            if (collectPayloads && match && possibleMatchPayloads.Count > 0)
            {
                matchPayload.AddRange(possibleMatchPayloads.Keys);
            }

            return(match);            // ordered and allowed slop
        }
예제 #6
0
 public override bool Next()
 {
     return(Adjust(spans.Next()));
 }