Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a new SegmentReader with a new core. </summary>
        /// <exception cref="CorruptIndexException"> if the index is corrupt </exception>
        /// <exception cref="IOException"> if there is a low-level IO error </exception>
        // TODO: why is this public?
        public SegmentReader(SegmentCommitInfo si, int termInfosIndexDivisor, IOContext context)
        {
            this.Si = si;
            // TODO if the segment uses CFS, we may open the CFS file twice: once for
            // reading the FieldInfos (if they are not gen'd) and second time by
            // SegmentCoreReaders. We can open the CFS here and pass to SCR, but then it
            // results in less readable code (resource not closed where it was opened).
            // Best if we could somehow read FieldInfos in SCR but not keep it there, but
            // constructors don't allow returning two things...
            FieldInfos_Renamed = ReadFieldInfos(si);
            Core         = new SegmentCoreReaders(this, si.Info.Dir, si, context, termInfosIndexDivisor);
            SegDocValues = new SegmentDocValues();

            bool  success = false;
            Codec codec   = si.Info.Codec;

            try
            {
                if (si.HasDeletions())
                {
                    // NOTE: the bitvector is stored using the regular directory, not cfs
                    LiveDocs_Renamed = codec.LiveDocsFormat().ReadLiveDocs(Directory(), si, IOContext.READONCE);
                }
                else
                {
                    Debug.Assert(si.DelCount == 0);
                    LiveDocs_Renamed = null;
                }
                numDocs = si.Info.DocCount - si.DelCount;

                if (FieldInfos_Renamed.HasDocValues())
                {
                    InitDocValuesProducers(codec);
                }

                success = true;
            }
            finally
            {
                // With lock-less commits, it's entirely possible (and
                // fine) to hit a FileNotFound exception above.  In
                // this case, we want to explicitly close any subset
                // of things that were opened so that we don't have to
                // wait for a GC to do so.
                if (!success)
                {
                    DoClose();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create new SegmentReader sharing core from a previous
        ///  SegmentReader and using the provided in-memory
        ///  liveDocs.  Used by IndexWriter to provide a new NRT
        ///  reader
        /// </summary>
        internal SegmentReader(SegmentCommitInfo si, SegmentReader sr, Bits liveDocs, int numDocs)
        {
            this.Si = si;
            this.LiveDocs_Renamed = liveDocs;
            this.numDocs          = numDocs;
            this.Core             = sr.Core;
            Core.IncRef();
            this.SegDocValues = sr.SegDocValues;

            //    System.out.println("[" + Thread.currentThread().getName() + "] SR.init: sharing reader: " + sr + " for gens=" + sr.genDVProducers.keySet());

            // increment refCount of DocValuesProducers that are used by this reader
            bool success = false;

            try
            {
                Codec codec = si.Info.Codec;
                if (si.FieldInfosGen == -1)
                {
                    FieldInfos_Renamed = sr.FieldInfos_Renamed;
                }
                else
                {
                    FieldInfos_Renamed = ReadFieldInfos(si);
                }

                if (FieldInfos_Renamed.HasDocValues())
                {
                    InitDocValuesProducers(codec);
                }
                success = true;
            }
            finally
            {
                if (!success)
                {
                    DoClose();
                }
            }
        }