/// <summary>Returns the position of a Term in the set or -1. </summary>
        internal long GetPosition(Term term)
        {
            if (size == 0)
            {
                return(-1);
            }

            int indexOffset = GetIndexOffset(term);

            SeekEnum(indexOffset);

            SegmentTermEnum enumerator = GetEnum();

            while (term.CompareTo(enumerator.Term()) > 0 && enumerator.Next())
            {
            }

            if (term.CompareTo(enumerator.Term()) == 0)
            {
                return(enumerator.position);
            }
            else
            {
                return(-1);
            }
        }
Ejemplo n.º 2
0
		public /*internal*/ TermInfosReader(Directory dir, System.String seg, FieldInfos fis)
		{
			directory = dir;
			segment = seg;
			fieldInfos = fis;
			
			origEnum = new SegmentTermEnum(directory.OpenFile(segment + ".tis"), fieldInfos, false);
			size = origEnum.size;
			ReadIndex();
		}
        public /*internal*/ TermInfosReader(Directory dir, System.String seg, FieldInfos fis)
        {
            directory  = dir;
            segment    = seg;
            fieldInfos = fis;

            origEnum = new SegmentTermEnum(directory.OpenFile(segment + ".tis"), fieldInfos, false);
            size     = origEnum.size;
            ReadIndex();
        }
        private SegmentTermEnum GetEnum()
        {
            SegmentTermEnum termEnum = (SegmentTermEnum)System.Threading.Thread.GetData(enumerators);

            if (termEnum == null)
            {
                termEnum = Terms();
                System.Threading.Thread.SetData(enumerators, termEnum);
            }
            return(termEnum);
        }
        private Term ScanEnum(int position)
        {
            SegmentTermEnum enumerator = GetEnum();

            while (enumerator.position < position)
            {
                if (!enumerator.Next())
                {
                    return(null);
                }
            }

            return(enumerator.Term());
        }
        /// <summary>Returns the nth term in the set. </summary>
        internal Term Get(int position)
        {
            if (size == 0)
            {
                return(null);
            }

            SegmentTermEnum enumerator = GetEnum();

            if (enumerator != null && enumerator.Term() != null && position >= enumerator.position && position < (enumerator.position + enumerator.indexInterval))
            {
                return(ScanEnum(position));                // can avoid seek
            }
            SeekEnum(position / enumerator.indexInterval); // must seek
            return(ScanEnum(position));
        }
        /// <summary>Scans within block for matching term. </summary>
        private TermInfo ScanEnum(Term term)
        {
            SegmentTermEnum enumerator = GetEnum();

            while (term.CompareTo(enumerator.Term()) > 0 && enumerator.Next())
            {
            }
            if (enumerator.Term() != null && term.CompareTo(enumerator.Term()) == 0)
            {
                return(enumerator.TermInfo());
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 8
0
        public System.Object Clone()
        {
            SegmentTermEnum clone = null;

            try
            {
                clone = (SegmentTermEnum)base.MemberwiseClone();
            }
            catch (System.Exception)
            {
            }

            clone.input    = (InputStream)input.Clone();
            clone.termInfo = new TermInfo(termInfo);
            if (term != null)
            {
                clone.GrowBuffer(term.text.Length);
            }

            return(clone);
        }
Ejemplo n.º 9
0
		private void  ReadIndex()
		{
			SegmentTermEnum indexEnum = new SegmentTermEnum(directory.OpenFile(segment + ".tii"), fieldInfos, true);
			try
			{
				int indexSize = (int) indexEnum.size;
				
				indexTerms = new Term[indexSize];
				indexInfos = new TermInfo[indexSize];
				indexPointers = new long[indexSize];
				
				for (int i = 0; indexEnum.Next(); i++)
				{
					indexTerms[i] = indexEnum.Term();
					indexInfos[i] = indexEnum.TermInfo();
					indexPointers[i] = indexEnum.indexPointer;
				}
			}
			finally
			{
				indexEnum.Close();
			}
		}
        /// <summary>Returns the TermInfo for a Term in the set, or null. </summary>
        public /*internal*/ TermInfo Get(Term term)
        {
            if (size == 0)
            {
                return(null);
            }

            // optimize sequential access: first try scanning cached enum w/o seeking
            SegmentTermEnum enumerator = GetEnum();

            if (enumerator.Term() != null && ((enumerator.prev != null && term.CompareTo(enumerator.prev) > 0) || term.CompareTo(enumerator.Term()) >= 0))
            {
                int enumOffset = (int)(enumerator.position / enumerator.indexInterval) + 1;
                if (indexTerms.Length == enumOffset || term.CompareTo(indexTerms[enumOffset]) < 0)
                {
                    return(ScanEnum(term)); // no need to seek
                }
            }

            // random-access: must seek
            SeekEnum(GetIndexOffset(term));
            return(ScanEnum(term));
        }
        private void  ReadIndex()
        {
            SegmentTermEnum indexEnum = new SegmentTermEnum(directory.OpenFile(segment + ".tii"), fieldInfos, true);

            try
            {
                int indexSize = (int)indexEnum.size;

                indexTerms    = new Term[indexSize];
                indexInfos    = new TermInfo[indexSize];
                indexPointers = new long[indexSize];

                for (int i = 0; indexEnum.Next(); i++)
                {
                    indexTerms[i]    = indexEnum.Term();
                    indexInfos[i]    = indexEnum.TermInfo();
                    indexPointers[i] = indexEnum.indexPointer;
                }
            }
            finally
            {
                indexEnum.Close();
            }
        }