Example #1
0
        private void  MergeTermInfos()
        {
            int base_Renamed = 0;

            for (int i = 0; i < readers.Count; i++)
            {
                IndexReader      reader   = (IndexReader)readers[i];
                TermEnum         termEnum = reader.Terms();
                SegmentMergeInfo smi      = new SegmentMergeInfo(base_Renamed, termEnum, reader);
                base_Renamed += reader.NumDocs();
                if (smi.Next())
                {
                    queue.Put(smi);
                }
                // initialize queue
                else
                {
                    smi.Close();
                }
            }

            SegmentMergeInfo[] match = new SegmentMergeInfo[readers.Count];

            while (queue.Size() > 0)
            {
                int matchSize = 0;                 // pop matching terms
                match[matchSize++] = (SegmentMergeInfo)queue.Pop();
                Term             term = match[0].term;
                SegmentMergeInfo top  = (SegmentMergeInfo)queue.Top();

                while (top != null && term.CompareTo(top.term) == 0)
                {
                    match[matchSize++] = (SegmentMergeInfo)queue.Pop();
                    top = (SegmentMergeInfo)queue.Top();
                }

                MergeTermInfo(match, matchSize);                 // add new TermInfo

                while (matchSize > 0)
                {
                    SegmentMergeInfo smi = match[--matchSize];
                    if (smi.Next())
                    {
                        queue.Put(smi);
                    }
                    // restore queue
                    else
                    {
                        smi.Close();                         // done with a segment
                    }
                }
            }
        }
Example #2
0
        public override bool Next()
        {
            SegmentMergeInfo top = (SegmentMergeInfo)queue.Top();

            if (top == null)
            {
                term = null;
                return(false);
            }

            term    = top.term;
            docFreq = 0;

            while (top != null && term.CompareTo(top.term) == 0)
            {
                queue.Pop();
                docFreq += top.termEnum.DocFreq();                 // increment freq
                if (top.Next())
                {
                    queue.Put(top);
                }
                // restore queue
                else
                {
                    top.Close();                     // done with a segment
                }
                top = (SegmentMergeInfo)queue.Top();
            }
            return(true);
        }