Example #1
0
        private void  Remove(HitDoc hitDoc)
        {
            // remove from cache
            if (hitDoc.doc == null)
            {
                // it's not in the list
                return;                  // abort
            }

            if (hitDoc.next == null)
            {
                last = hitDoc.prev;
            }
            else
            {
                hitDoc.next.prev = hitDoc.prev;
            }

            if (hitDoc.prev == null)
            {
                first = hitDoc.next;
            }
            else
            {
                hitDoc.prev.next = hitDoc.next;
            }

            numDocs--;
        }
Example #2
0
        private void  AddToFront(HitDoc hitDoc)
        {
            // insert at front of cache
            if (first == null)
            {
                last = hitDoc;
            }
            else
            {
                first.prev = hitDoc;
            }

            hitDoc.next = first;
            first       = hitDoc;
            hitDoc.prev = null;

            numDocs++;
        }
Example #3
0
        /// <summary>Returns the stored fields of the n<sup>th</sup> document in this set.
        /// <p/>Documents are cached, so that repeated requests for the same element may
        /// return the same Document object.
        /// </summary>
        /// <throws>  CorruptIndexException if the index is corrupt </throws>
        /// <throws>  IOException if there is a low-level IO error </throws>
        public Document Doc(int n)
        {
            HitDoc hitDoc = HitDoc(n);

            // Update LRU cache of documents
            Remove(hitDoc);             // remove from list, if there
            AddToFront(hitDoc);         // add to front of list
            if (numDocs > maxDocs)
            {
                // if cache is full
                HitDoc oldLast = last;
                Remove(last);                 // flush last
                oldLast.doc = null;           // let doc get gc'd
            }

            if (hitDoc.doc == null)
            {
                hitDoc.doc = searcher.Doc(hitDoc.id);                 // cache miss: read document
            }

            return(hitDoc.doc);
        }
Example #4
0
		private void  Remove(HitDoc hitDoc)
		{
			// remove from cache
			if (hitDoc.doc == null)
			{
				// it's not in the list
				return ; // abort
			}
			
			if (hitDoc.next == null)
			{
				last = hitDoc.prev;
			}
			else
			{
				hitDoc.next.prev = hitDoc.prev;
			}
			
			if (hitDoc.prev == null)
			{
				first = hitDoc.next;
			}
			else
			{
				hitDoc.prev.next = hitDoc.next;
			}
			
			numDocs--;
		}
Example #5
0
		private void  AddToFront(HitDoc hitDoc)
		{
			// insert at front of cache
			if (first == null)
			{
				last = hitDoc;
			}
			else
			{
				first.prev = hitDoc;
			}
			
			hitDoc.next = first;
			first = hitDoc;
			hitDoc.prev = null;
			
			numDocs++;
		}