예제 #1
0
 internal bool Next()
 {
     if (termEnum.Next())
     {
         term = termEnum.Term;
         return(true);
     }
     else
     {
         term = null;
         return(false);
     }
 }
예제 #2
0
            public override bool Next()
            {
                if (termEnum == null)
                {
                    return(false);
                }

                // another term in this field?
                if (termEnum.Next() && (System.Object)termEnum.Term.Field == (System.Object)field)
                {
                    return(true);                 // yes, keep going
                }
                termEnum.Close();                 // close old termEnum

                // find the next field with terms, if any
                if (fieldIterator == null)
                {
                    var newList = new List <string>();
                    if (Enclosing_Instance.fieldToReader != null && Enclosing_Instance.fieldToReader.Count > 0)
                    {
                        var comparer = Enclosing_Instance.fieldToReader.Comparer;
                        foreach (var entry in Enclosing_Instance.fieldToReader.Keys.Where(x => comparer.Compare(x, field) >= 0))
                        {
                            newList.Add(entry);
                        }
                    }

                    fieldIterator = newList.Skip(1).GetEnumerator(); // Skip field to get next one
                }
                while (fieldIterator.MoveNext())
                {
                    field    = fieldIterator.Current;
                    termEnum = Enclosing_Instance.fieldToReader[field].Terms(new Term(field));
                    Term term = termEnum.Term;
                    if (term != null && (System.Object)term.Field == (System.Object)field)
                    {
                        return(true);
                    }
                    else
                    {
                        termEnum.Close();
                    }
                }

                return(false);                // no more fields
            }
예제 #3
0
 public override bool Next()
 {
     return(in_Renamed.Next());
 }
예제 #4
0
        /// <summary> Test the term index.</summary>
        private Status.TermIndexStatus TestTermIndex(SegmentInfo info, SegmentReader reader)
        {
            var status = new Status.TermIndexStatus();

            try
            {
                if (infoStream != null)
                {
                    infoStream.Write("    test: terms, freq, prox...");
                }

                TermEnum      termEnum      = reader.Terms();
                TermPositions termPositions = reader.TermPositions();

                // Used only to count up # deleted docs for this term
                var myTermDocs = new MySegmentTermDocs(reader);

                int maxDoc = reader.MaxDoc;

                while (termEnum.Next())
                {
                    status.termCount++;
                    Term term    = termEnum.Term;
                    int  docFreq = termEnum.DocFreq();
                    termPositions.Seek(term);
                    int lastDoc = -1;
                    int freq0   = 0;
                    status.totFreq += docFreq;
                    while (termPositions.Next())
                    {
                        freq0++;
                        int doc  = termPositions.Doc;
                        int freq = termPositions.Freq;
                        if (doc <= lastDoc)
                        {
                            throw new System.SystemException("term " + term + ": doc " + doc + " <= lastDoc " + lastDoc);
                        }
                        if (doc >= maxDoc)
                        {
                            throw new System.SystemException("term " + term + ": doc " + doc + " >= maxDoc " + maxDoc);
                        }

                        lastDoc = doc;
                        if (freq <= 0)
                        {
                            throw new System.SystemException("term " + term + ": doc " + doc + ": freq " + freq + " is out of bounds");
                        }

                        int lastPos = -1;
                        status.totPos += freq;
                        for (int j = 0; j < freq; j++)
                        {
                            int pos = termPositions.NextPosition();
                            if (pos < -1)
                            {
                                throw new System.SystemException("term " + term + ": doc " + doc + ": pos " + pos + " is out of bounds");
                            }
                            if (pos < lastPos)
                            {
                                throw new System.SystemException("term " + term + ": doc " + doc + ": pos " + pos + " < lastPos " + lastPos);
                            }
                            lastPos = pos;
                        }
                    }

                    // Now count how many deleted docs occurred in
                    // this term:
                    int delCount;
                    if (reader.HasDeletions)
                    {
                        myTermDocs.Seek(term);
                        while (myTermDocs.Next())
                        {
                        }
                        delCount = myTermDocs.delCount;
                    }
                    else
                    {
                        delCount = 0;
                    }

                    if (freq0 + delCount != docFreq)
                    {
                        throw new System.SystemException("term " + term + " docFreq=" + docFreq + " != num docs seen " + freq0 + " + num docs deleted " + delCount);
                    }
                }

                Msg("OK [" + status.termCount + " terms; " + status.totFreq + " terms/docs pairs; " + status.totPos + " tokens]");
            }
            catch (System.Exception e)
            {
                Msg("ERROR [" + System.Convert.ToString(e.Message) + "]");
                status.error = e;
                if (infoStream != null)
                {
                    infoStream.WriteLine(e.StackTrace);
                }
            }

            return(status);
        }