Exemplo n.º 1
0
        /// <summary> Create a clone from the initial TermVectorsReader and store it in the ThreadLocal.</summary>
        /// <returns> TermVectorsReader
        /// </returns>
        private TermVectorsReader GetTermVectorsReader()
        {
            TermVectorsReader tvReader = (TermVectorsReader)System.Threading.Thread.GetData(termVectorsLocal);

            if (tvReader == null)
            {
                tvReader = (TermVectorsReader)termVectorsReaderOrig.Clone();
                System.Threading.Thread.SetData(termVectorsLocal, tvReader);
            }
            return(tvReader);
        }
Exemplo n.º 2
0
        /// <summary> Create a clone from the initial TermVectorsReader and store it in the ThreadLocal.</summary>
        /// <returns> TermVectorsReader
        /// </returns>
        private TermVectorsReader GetTermVectorsReader()
        {
            System.Diagnostics.Debug.Assert(termVectorsReaderOrig != null);
            TermVectorsReader tvReader = (TermVectorsReader)termVectorsLocal.Get();

            if (tvReader == null)
            {
                try
                {
                    tvReader = (TermVectorsReader)termVectorsReaderOrig.Clone();
                }
                catch (System.Exception)
                {
                    return(null);
                }
                termVectorsLocal.Set(tvReader);
            }
            return(tvReader);
        }
Exemplo n.º 3
0
        internal SegmentCoreReaders(SegmentReader owner, Directory dir, SegmentCommitInfo si, IOContext context, int termsIndexDivisor)
        {
            fieldsReaderLocal = new DisposableThreadLocal <StoredFieldsReader>(()
                                                                               => (StoredFieldsReader)fieldsReaderOrig.Clone());
            termVectorsLocal = new DisposableThreadLocal <TermVectorsReader>(()
                                                                             => (termVectorsReaderOrig is null) ? null : (TermVectorsReader)termVectorsReaderOrig.Clone());

            if (termsIndexDivisor == 0)
            {
                throw new ArgumentException("indexDivisor must be < 0 (don't load terms index) or greater than 0 (got 0)");
            }

            Codec     codec = si.Info.Codec;
            Directory cfsDir; // confusing name: if (cfs) its the cfsdir, otherwise its the segment's directory.

            bool success = false;

            try
            {
                if (si.Info.UseCompoundFile)
                {
                    cfsDir = cfsReader = new CompoundFileDirectory(dir, IndexFileNames.SegmentFileName(si.Info.Name, "", IndexFileNames.COMPOUND_FILE_EXTENSION), context, false);
                }
                else
                {
                    cfsReader = null;
                    cfsDir    = dir;
                }

                FieldInfos fieldInfos = owner.FieldInfos;

                this.termsIndexDivisor = termsIndexDivisor;
                PostingsFormat   format           = codec.PostingsFormat;
                SegmentReadState segmentReadState = new SegmentReadState(cfsDir, si.Info, fieldInfos, context, termsIndexDivisor);
                // Ask codec for its Fields
                fields = format.FieldsProducer(segmentReadState);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(fields != null);
                }
                // ask codec for its Norms:
                // TODO: since we don't write any norms file if there are no norms,
                // kinda jaky to assume the codec handles the case of no norms file at all gracefully?!

                if (fieldInfos.HasNorms)
                {
                    normsProducer = codec.NormsFormat.NormsProducer(segmentReadState);
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(normsProducer != null);
                    }
                }
                else
                {
                    normsProducer = null;
                }

                fieldsReaderOrig = si.Info.Codec.StoredFieldsFormat.FieldsReader(cfsDir, si.Info, fieldInfos, context);

                if (fieldInfos.HasVectors) // open term vector files only as needed
                {
                    termVectorsReaderOrig = si.Info.Codec.TermVectorsFormat.VectorsReader(cfsDir, si.Info, fieldInfos, context);
                }
                else
                {
                    termVectorsReaderOrig = null;
                }

                success = true;
            }
            finally
            {
                if (!success)
                {
                    DecRef();
                }
            }
        }