Exemplo n.º 1
0
        internal override void flush(IDictionary <object, ICollection <object> > threadsAndFields, DocumentsWriter.FlushState state)
        {
            lock (this)
            {
                IDictionary <object, object> childThreadsAndFields = new Dictionary <object, object>();
                IDictionary <object, ICollection <object> > nextThreadsAndFields;

                if (nextTermsHash != null)
                {
                    nextThreadsAndFields = new Dictionary <object, ICollection <object> >();
                }
                else
                {
                    nextThreadsAndFields = null;
                }

                IEnumerator <KeyValuePair <object, ICollection <object> > > it = threadsAndFields.GetEnumerator();
                while (it.MoveNext())
                {
                    KeyValuePair <object, ICollection <object> > entry = it.Current;

                    TermsHashPerThread perThread = (TermsHashPerThread)entry.Key;

                    ICollection <object> fields = entry.Value;

                    IEnumerator <object>         fieldsIt    = fields.GetEnumerator();
                    IDictionary <object, object> childFields = new Dictionary <object, object>();
                    IDictionary <object, object> nextChildFields;

                    if (nextTermsHash != null)
                    {
                        nextChildFields = new Dictionary <object, object>();
                    }
                    else
                    {
                        nextChildFields = null;
                    }

                    while (fieldsIt.MoveNext())
                    {
                        TermsHashPerField perField = (TermsHashPerField)fieldsIt.Current;
                        childFields[perField.consumer] = perField.consumer;
                        if (nextTermsHash != null)
                        {
                            nextChildFields[perField.nextPerField] = perField.nextPerField;
                        }
                    }

                    childThreadsAndFields[perThread.consumer] = childFields.Keys;
                    if (nextTermsHash != null)
                    {
                        nextThreadsAndFields[perThread.nextPerThread] = nextChildFields.Keys;
                    }
                }

                consumer.flush(childThreadsAndFields, state);

                shrinkFreePostings(threadsAndFields, state);

                if (nextTermsHash != null)
                {
                    nextTermsHash.flush(nextThreadsAndFields, state);
                }
            }
        }