Ejemplo n.º 1
0
        /// <summary> Advances to the first match beyond the current whose document number is
        /// greater than or equal to a given target. <br/>
        /// The implementation uses {@link TermDocs#SkipTo(int)}.
        ///
        /// </summary>
        /// <param name="target">The target document number.
        /// </param>
        /// <returns> the matching document or -1 if none exist.
        /// </returns>
        public override int Advance(int target)
        {
            // first scan in cache
            for (pointer++; pointer < pointerMax; pointer++)
            {
                if (docs[pointer] >= target)
                {
                    return(doc = docs[pointer]);
                }
            }

            // not found in cache, seek underlying stream
            bool result = termDocs.SkipTo(target);

            if (result)
            {
                pointerMax     = 1;
                pointer        = 0;
                docs[pointer]  = doc = termDocs.Doc();
                freqs[pointer] = termDocs.Freq();
            }
            else
            {
                doc = NO_MORE_DOCS;
            }
            return(doc);
        }