internal SegmentMergeInfo(int b, TermEnum te, IndexReader r)
		{
			base_Renamed = b;
			reader = r;
			termEnum = te;
			term = te.Term;
		}
Example #2
0
		/// <summary> Returns sub-reader subIndex from reader.
		/// 
		/// </summary>
		/// <param name="reader">parent reader
		/// </param>
		/// <param name="subIndex">index of desired sub reader
		/// </param>
		/// <returns> the subreader at subINdex
		/// </returns>
		public static IndexReader SubReader(IndexReader reader, int subIndex)
		{
            var subReadersList = new System.Collections.Generic.List<IndexReader>();
			ReaderUtil.GatherSubReaders(subReadersList, reader);
			IndexReader[] subReaders = subReadersList.ToArray();
			return subReaders[subIndex];
		}
			internal MatchAllScorer(MatchAllDocsQuery enclosingInstance, IndexReader reader, Similarity similarity, Weight w, byte[] norms):base(similarity)
			{
				InitBlock(enclosingInstance);
				this.termDocs = reader.TermDocs(null);
				score = w.Value;
				this.norms = norms;
			}
Example #4
0
 private void  Initialize(IndexReader[] subReaders, bool closeSubReaders)
 {
     // Deep copy
     this.subReaders = subReaders.ToArray();
     starts = new int[subReaders.Length + 1]; // build starts array
     decrefOnClose = new bool[subReaders.Length];
     for (int i = 0; i < subReaders.Length; i++)
     {
         starts[i] = maxDoc;
         maxDoc += subReaders[i].MaxDoc; // compute maxDocs
         
         if (!closeSubReaders)
         {
             subReaders[i].IncRef();
             decrefOnClose[i] = true;
         }
         else
         {
             decrefOnClose[i] = false;
         }
         
         if (subReaders[i].HasDeletions)
             hasDeletions = true;
     }
     starts[subReaders.Length] = maxDoc;
 }
		/// <summary> Enumerates all terms greater/equal than <c>lowerTerm</c>
		/// but less/equal than <c>upperTerm</c>. 
		/// 
		/// If an endpoint is null, it is said to be "open". Either or both 
		/// endpoints may be open.  Open endpoints may not be exclusive 
		/// (you can't select all but the first or last term without 
		/// explicitly specifying the term to exclude.)
		/// 
		/// </summary>
		/// <param name="reader">
		/// </param>
		/// <param name="field">An interned field that holds both lower and upper terms.
		/// </param>
		/// <param name="lowerTermText">The term text at the lower end of the range
		/// </param>
		/// <param name="upperTermText">The term text at the upper end of the range
		/// </param>
		/// <param name="includeLower">If true, the <c>lowerTerm</c> is included in the range.
		/// </param>
		/// <param name="includeUpper">If true, the <c>upperTerm</c> is included in the range.
		/// </param>
		/// <param name="collator">The collator to use to collate index Terms, to determine their
		/// membership in the range bounded by <c>lowerTerm</c> and
		/// <c>upperTerm</c>.
		/// 
		/// </param>
		/// <throws>  IOException </throws>
		public TermRangeTermEnum(IndexReader reader, System.String field, System.String lowerTermText, System.String upperTermText, bool includeLower, bool includeUpper, System.Globalization.CompareInfo collator)
		{
			this.collator = collator;
			this.upperTermText = upperTermText;
			this.lowerTermText = lowerTermText;
			this.includeLower = includeLower;
			this.includeUpper = includeUpper;
			this.field = StringHelper.Intern(field);
			
			// do a little bit of normalization...
			// open ended range queries should always be inclusive.
			if (this.lowerTermText == null)
			{
				this.lowerTermText = "";
				this.includeLower = true;
			}
			
			if (this.upperTermText == null)
			{
				this.includeUpper = true;
			}
			
			System.String startTermText = collator == null?this.lowerTermText:"";
			SetEnum(reader.Terms(new Term(this.field, startTermText)));
		}
Example #6
0
 // lucene.net: java version 3.0.3 with patch in rev. 912330 applied:
 // uschindler 21/02/2010 12:16:42 LUCENE-2273: Fixed bug in FieldCacheImpl.getCacheEntries() that used 
 //                     WeakHashMap incorrectly and lead to ConcurrentModificationException
 public void Purge(IndexReader r)
 {
     lock (this)
     {
         foreach (Cache c in caches.Values)
         {
             c.Purge(r);
         }
     }
 }
Example #7
0
		public override Explanation Explain(IndexReader reader, int doc)
		{
			
			ComplexExplanation result = new ComplexExplanation();
			result.Description = "weight(" + Query + " in " + doc + "), product of:";
			System.String field = ((SpanQuery) Query).Field;
			
			Explanation idfExpl = new Explanation(idf, "idf(" + field + ": " + idfExp.Explain() + ")");
			
			// explain query weight
			Explanation queryExpl = new Explanation();
			queryExpl.Description = "queryWeight(" + Query + "), product of:";
			
			Explanation boostExpl = new Explanation(Query.Boost, "boost");
			if (Query.Boost != 1.0f)
				queryExpl.AddDetail(boostExpl);
			queryExpl.AddDetail(idfExpl);
			
			Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");
			queryExpl.AddDetail(queryNormExpl);
			
			queryExpl.Value = boostExpl.Value * idfExpl.Value * queryNormExpl.Value;
			
			result.AddDetail(queryExpl);
			
			// explain field weight
			ComplexExplanation fieldExpl = new ComplexExplanation();
			fieldExpl.Description = "fieldWeight(" + field + ":" + internalQuery.ToString(field) + " in " + doc + "), product of:";
			
			Explanation tfExpl = ((SpanScorer)Scorer(reader, true, false)).Explain(doc);
			fieldExpl.AddDetail(tfExpl);
			fieldExpl.AddDetail(idfExpl);
			
			Explanation fieldNormExpl = new Explanation();
			byte[] fieldNorms = reader.Norms(field);
			float fieldNorm = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]):1.0f;
			fieldNormExpl.Value = fieldNorm;
			fieldNormExpl.Description = "fieldNorm(field=" + field + ", doc=" + doc + ")";
			fieldExpl.AddDetail(fieldNormExpl);
			
			fieldExpl.Match = tfExpl.IsMatch;
			fieldExpl.Value = tfExpl.Value * idfExpl.Value * fieldNormExpl.Value;
			
			result.AddDetail(fieldExpl);
			System.Boolean? tempAux = fieldExpl.Match;
			result.Match = tempAux;
			
			// combine them
			result.Value = queryExpl.Value * fieldExpl.Value;
			
			if (queryExpl.Value == 1.0f)
				return fieldExpl;
			
			return result;
		}
Example #8
0
		protected internal override FilteredTermEnum GetEnum(IndexReader reader)
		{
            if (_termContainsWildcard)
            {
                return new WildcardTermEnum(reader, Term);
            }
            else
            {
                return new SingleTermEnum(reader, Term);
            }
		}
Example #9
0
		/// <summary> Returns sub IndexReader that contains the given document id.
		/// 
		/// </summary>
		/// <param name="doc">id of document
		/// </param>
		/// <param name="reader">parent reader
		/// </param>
		/// <returns> sub reader of parent which contains the specified doc id
		/// </returns>
		public static IndexReader SubReader(int doc, IndexReader reader)
		{
            var subReadersList = new System.Collections.Generic.List<IndexReader>();
			ReaderUtil.GatherSubReaders(subReadersList, reader);
			IndexReader[] subReaders = subReadersList.ToArray();
			int[] docStarts = new int[subReaders.Length];
			int maxDoc = 0;
			for (int i = 0; i < subReaders.Length; i++)
			{
				docStarts[i] = maxDoc;
				maxDoc += subReaders[i].MaxDoc;
			}
			return subReaders[ReaderUtil.SubIndex(doc, docStarts)];
		}
Example #10
0
	    public override Query Rewrite(IndexReader reader)
		{
            if (_termIsPrefix)
            {
                MultiTermQuery rewritten =
                    new PrefixQuery(internalTerm.CreateTerm(internalTerm.Text.Substring(0, internalTerm.Text.IndexOf('*'))));
                rewritten.Boost = Boost;
                rewritten.RewriteMethod = RewriteMethod;
                return rewritten;
            }
            else
            {
                return base.Rewrite(reader);
            }
		}
Example #11
0
		/// <summary>Gathers sub-readers from reader into a List.</summary>
		/// <param name="allSubReaders"></param>
		/// <param name="reader"></param>
		public static void GatherSubReaders(System.Collections.Generic.IList<IndexReader> allSubReaders, IndexReader reader)
		{
			IndexReader[] subReaders = reader.GetSequentialSubReaders();
			if (subReaders == null)
			{
				// Add the reader itself, and do not recurse
				allSubReaders.Add(reader);
			}
			else
			{
				for (int i = 0; i < subReaders.Length; i++)
				{
					GatherSubReaders(allSubReaders, subReaders[i]);
				}
			}
		}
Example #12
0
		public override SpanFilterResult BitSpans(IndexReader reader)
		{
			
			OpenBitSet bits = new OpenBitSet(reader.MaxDoc);
			Lucene.Net.Search.Spans.Spans spans = internalQuery.GetSpans(reader);
			IList<SpanFilterResult.PositionInfo> tmp = new List<SpanFilterResult.PositionInfo>(20);
			int currentDoc = - 1;
			SpanFilterResult.PositionInfo currentInfo = null;
			while (spans.Next())
			{
				int doc = spans.Doc();
				bits.Set(doc);
				if (currentDoc != doc)
				{
					currentInfo = new SpanFilterResult.PositionInfo(doc);
					tmp.Add(currentInfo);
					currentDoc = doc;
				}
				currentInfo.AddPosition(spans.Start(), spans.End());
			}
			return new SpanFilterResult(bits, tmp);
		}
Example #13
0
		/*(non-Javadoc) <see cref="Lucene.Net.Search.Query.rewrite(Lucene.Net.Index.IndexReader) */
        public override Query Rewrite(IndexReader reader)
        {
            CustomScoreQuery clone = null;

            Query sq = subQuery.Rewrite(reader);
            if (sq != subQuery)
            {
                clone = (CustomScoreQuery)Clone();
                clone.subQuery = sq;
            }

            for (int i = 0; i < valSrcQueries.Length; i++)
            {
                ValueSourceQuery v = (ValueSourceQuery)valSrcQueries[i].Rewrite(reader);
                if (v != valSrcQueries[i])
                {
                    if (clone == null) clone = (CustomScoreQuery)Clone();
                    clone.valSrcQueries[i] = v;
                }
            }

            return (clone == null) ? this : clone;
        }
Example #14
0
		/// <summary> Creates a new <c>WildcardTermEnum</c>.
		/// <p/>
		/// After calling the constructor the enumeration is already pointing to the first 
		/// valid term if such a term exists.
		/// </summary>
		public WildcardTermEnum(IndexReader reader, Term term):base()
		{
			searchTerm = term;
			field = searchTerm.Field;
			System.String searchTermText = searchTerm.Text;
			
			int sidx = searchTermText.IndexOf((System.Char) WILDCARD_STRING);
			int cidx = searchTermText.IndexOf((System.Char) WILDCARD_CHAR);
			int idx = sidx;
			if (idx == - 1)
			{
				idx = cidx;
			}
			else if (cidx >= 0)
			{
				idx = System.Math.Min(idx, cidx);
			}
			pre = idx != - 1?searchTerm.Text.Substring(0, (idx) - (0)):"";
			
			preLen = pre.Length;
			text = searchTermText.Substring(preLen);
			SetEnum(reader.Terms(new Term(searchTerm.Field, pre)));
		}
Example #15
0
		/*(non-Javadoc) <see cref="Lucene.Net.Search.Function.ValueSource.getValues(Lucene.Net.Index.IndexReader) */
		public override DocValues GetValues(IndexReader reader)
		{
			int[] arr = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetStringIndex(reader, field).order;
			return new AnonymousClassDocValues(arr, this);
		}
	    public override DocIdSet GetDocIdSet(IndexReader reader)
		{
			return new FieldCacheTermsFilterDocIdSet(this, FieldCache.GetStringIndex(reader, field));
		}
	    // :NOTE: getBoost and setBoost are not proxied to the maskedQuery
		// ...this is done to be more consistent with thigns like SpanFirstQuery
		
		public override Spans GetSpans(IndexReader reader)
		{
			return maskedQuery.GetSpans(reader);
		}
		public override Query Rewrite(IndexReader reader)
		{
			FieldMaskingSpanQuery clone = null;
			
			SpanQuery rewritten = (SpanQuery) maskedQuery.Rewrite(reader);
			if (rewritten != maskedQuery)
			{
				clone = (FieldMaskingSpanQuery) this.Clone();
				clone.maskedQuery = rewritten;
			}
			
			if (clone != null)
			{
				return clone;
			}
			else
			{
				return this;
			}
		}
Example #19
0
	    protected internal override FilteredTermEnum GetEnum(IndexReader reader)
		{
			return new PrefixTermEnum(reader, prefix);
		}
Example #20
0
 protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
 {
     System.String field = StringHelper.Intern(entryKey.field);
     int[] retArray = new int[reader.MaxDoc];
     System.String[] mterms = new System.String[reader.MaxDoc + 1];
     TermDocs termDocs = reader.TermDocs();
     TermEnum termEnum = reader.Terms(new Term(field));
     int t = 0; // current term number
     
     // an entry for documents that have no terms in this field
     // should a document with no terms be at top or bottom?
     // this puts them at the top - if it is changed, FieldDocSortedHitQueue
     // needs to change as well.
     mterms[t++] = null;
     
     try
     {
         do 
         {
             Term term = termEnum.Term;
             if (term == null || term.Field != field || t >= mterms.Length) break;
             
             // store term text
             mterms[t] = term.Text;
             
             termDocs.Seek(termEnum);
             while (termDocs.Next())
             {
                 retArray[termDocs.Doc] = t;
             }
             
             t++;
         }
         while (termEnum.Next());
     }
     finally
     {
         termDocs.Close();
         termEnum.Close();
     }
     
     if (t == 0)
     {
         // if there are no terms, make the term array
         // have a single null entry
         mterms = new System.String[1];
     }
     else if (t < mterms.Length)
     {
         // if there are less terms than documents,
         // trim off the dead array space
         System.String[] terms = new System.String[t];
         Array.Copy(mterms, 0, terms, 0, t);
         mterms = terms;
     }
     
     StringIndex value_Renamed = new StringIndex(retArray, mterms);
     return value_Renamed;
 }
Example #21
0
 // inherit javadocs
 public virtual StringIndex GetStringIndex(IndexReader reader, System.String field)
 {
     return (StringIndex) caches[typeof(StringIndex)].Get(reader, new Entry(field, (Parser) null));
 }
Example #22
0
			public abstract void  Warm(IndexReader reader);
		/*(non-Javadoc) <see cref="Lucene.Net.Search.Function.ValueSource.getValues(Lucene.Net.Index.IndexReader) */
		public override DocValues GetValues(IndexReader reader)
		{
			Lucene.Net.Search.StringIndex sindex = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetStringIndex(reader, field);
			
			int[] arr = sindex.order;
			int end = sindex.lookup.Length;
			
			return new AnonymousClassDocValues(end, arr, this);
		}
		public override void  SetNextReader(IndexReader reader, int docBase)
		{
			c.SetNextReader(reader, docBase);
		}
Example #25
0
		/*(non-Javadoc) <see cref="Lucene.Net.Search.Function.FieldCacheSource.getCachedValues(Lucene.Net.Search.FieldCache, java.lang.String, Lucene.Net.Index.IndexReader) */
		public override DocValues GetCachedFieldValues(FieldCache cache, System.String field, IndexReader reader)
		{
			int[] arr = cache.GetInts(reader, field, parser);
			return new AnonymousClassDocValues(arr, this);
		}
Example #26
0
 protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
 {
     Entry entry = entryKey;
     System.String field = entry.field;
     Lucene.Net.Search.DoubleParser parser = (Lucene.Net.Search.DoubleParser) entry.custom;
     if (parser == null)
     {
         try
         {
             return wrapper.GetDoubles(reader, field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_DOUBLE_PARSER);
         }
         catch (System.FormatException)
         {
             return wrapper.GetDoubles(reader, field, Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_DOUBLE_PARSER);
         }
     }
     double[] retArray = null;
     TermDocs termDocs = reader.TermDocs();
     TermEnum termEnum = reader.Terms(new Term(field));
     try
     {
         do 
         {
             Term term = termEnum.Term;
             if (term == null || (System.Object) term.Field != (System.Object) field)
                 break;
             double termval = parser.ParseDouble(term.Text);
             if (retArray == null)
             // late init
                 retArray = new double[reader.MaxDoc];
             termDocs.Seek(termEnum);
             while (termDocs.Next())
             {
                 retArray[termDocs.Doc] = termval;
             }
         }
         while (termEnum.Next());
     }
     catch (StopFillCacheException)
     {
     }
     finally
     {
         termDocs.Close();
         termEnum.Close();
     }
     if (retArray == null)
     // no values
         retArray = new double[reader.MaxDoc];
     return retArray;
 }
Example #27
0
		// Apply buffered delete terms, queries and docIDs to the
		// provided reader
		private bool ApplyDeletes(IndexReader reader, int docIDStart)
		{
			lock (this)
			{
				int docEnd = docIDStart + reader.MaxDoc;
				bool any = false;
				
                System.Diagnostics.Debug.Assert(CheckDeleteTerm(null));

				// Delete by term
				TermDocs docs = reader.TermDocs();
				try
				{
					foreach(KeyValuePair<Term, BufferedDeletes.Num> entry in deletesFlushed.terms)
					{
						Term term = entry.Key;
						// LUCENE-2086: we should be iterating a TreeMap,
                        // here, so terms better be in order:
                        System.Diagnostics.Debug.Assert(CheckDeleteTerm(term));
						docs.Seek(term);
						int limit = entry.Value.GetNum();
						while (docs.Next())
						{
							int docID = docs.Doc;
							if (docIDStart + docID >= limit)
								break;
							reader.DeleteDocument(docID);
							any = true;
						}
					}
				}
				finally
				{
					docs.Close();
				}
				
				// Delete by docID
				foreach(int docIdInt in deletesFlushed.docIDs)
				{
				    int docID = docIdInt;
					if (docID >= docIDStart && docID < docEnd)
					{
						reader.DeleteDocument(docID - docIDStart);
						any = true;
					}
				}
				
				// Delete by query
				IndexSearcher searcher = new IndexSearcher(reader);
				foreach(KeyValuePair<Query, int> entry in deletesFlushed.queries)
				{
					Query query = (Query) entry.Key;
					int limit = (int)entry.Value;
					Weight weight = query.Weight(searcher);
					Scorer scorer = weight.Scorer(reader, true, false);
					if (scorer != null)
					{
						while (true)
						{
							int doc = scorer.NextDoc();
							if (((long) docIDStart) + doc >= limit)
								break;
							reader.DeleteDocument(doc);
							any = true;
						}
					}
				}
				searcher.Close();
				return any;
			}
		}
Example #28
0
 // inherit javadocs
 public virtual System.String[] GetStrings(IndexReader reader, System.String field)
 {
     return (System.String[]) caches[typeof(string)].Get(reader, new Entry(field, (Parser) null));
 }
			public override void  SetNextReader(IndexReader reader, int docBase)
			{
				collector.SetNextReader(reader, start + docBase);
			}
Example #30
0
 protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
 {
     System.String field = StringHelper.Intern(entryKey.field);
     System.String[] retArray = new System.String[reader.MaxDoc];
     TermDocs termDocs = reader.TermDocs();
     TermEnum termEnum = reader.Terms(new Term(field));
     try
     {
         do 
         {
             Term term = termEnum.Term;
             if (term == null || (System.Object) term.Field != (System.Object) field)
                 break;
             System.String termval = term.Text;
             termDocs.Seek(termEnum);
             while (termDocs.Next())
             {
                 retArray[termDocs.Doc] = termval;
             }
         }
         while (termEnum.Next());
     }
     finally
     {
         termDocs.Close();
         termEnum.Close();
     }
     return retArray;
 }