public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            BooleanQuery query      = new BooleanQuery();
            TermEnum     enumerator = reader.Terms(prefix);

            try
            {
                System.String prefixText  = prefix.Text();
                System.String prefixField = prefix.Field();
                do
                {
                    Term term = enumerator.Term();
                    if (term != null && term.Text().StartsWith(prefixText) && (System.Object)term.Field() == (System.Object)prefixField)
                    {
                        TermQuery tq = new TermQuery(term); // found a match
                        tq.SetBoost(GetBoost());            // set the boost
                        query.Add(tq, false, false);        // add to query
                        //System.out.println("added " + term);
                    }
                    else
                    {
                        break;
                    }
                }while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }
            return(query);
        }
Пример #2
0
        /// <summary> FIXME: Describe <code>rewrite</code> method here.
        ///
        /// </summary>
        /// <param name="reader">an <code>Monodoc.Lucene.Net.Index.IndexReader</code> value
        /// </param>
        /// <returns> a <code>Query</code> value
        /// </returns>
        /// <exception cref=""> IOException if an error occurs
        /// </exception>
        public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader)
        {
            BooleanQuery query      = new BooleanQuery();
            TermEnum     enumerator = reader.Terms(lowerTerm);

            try
            {
                bool checkLower = false;
                if (!inclusive)
                {
                    // make adjustments to set to exclusive
                    checkLower = true;
                }

                System.String testField = GetField();

                do
                {
                    Term term = enumerator.Term();
                    if (term != null && (System.Object)term.Field() == (System.Object)testField)
                    {
                        if (!checkLower || String.CompareOrdinal(term.Text(), lowerTerm.Text()) > 0)
                        {
                            checkLower = false;
                            if (upperTerm != null)
                            {
                                int compare = String.CompareOrdinal(upperTerm.Text(), term.Text());

                                /* if beyond the upper term, or is exclusive and
                                 * this is equal to the upper term, break out */
                                if ((compare < 0) || (!inclusive && compare == 0))
                                {
                                    break;
                                }
                            }
                            TermQuery tq = new TermQuery(term); // found a match
                            tq.SetBoost(GetBoost());            // set the boost
                            query.Add(tq, false, false);        // add to query
                        }
                    }
                    else
                    {
                        break;
                    }
                }while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }
            return(query);
        }
Пример #3
0
        /// <summary>The pattern used to detect integer values in a Field </summary>
        /// <summary>removed for java 1.3 compatibility
        /// protected static final Pattern pIntegers = Pattern.compile ("[0-9\\-]+");
        ///
        /// </summary>

        /// <summary>The pattern used to detect float values in a Field </summary>
        /// <summary> removed for java 1.3 compatibility
        /// protected static final Object pFloats = Pattern.compile ("[0-9+\\-\\.eEfFdD]+");
        /// </summary>

        // inherit javadocs
        public virtual System.Object GetAuto(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field)
        {
            field = String.Intern(field);
            System.Object ret = Lookup(reader, field, SortField.AUTO);
            if (ret == null)
            {
                TermEnum enumerator = reader.Terms(new Term(field, ""));
                try
                {
                    Term term = enumerator.Term();
                    if (term == null)
                    {
                        throw new System.SystemException("no terms in Field " + field + " - cannot determine sort type");
                    }
                    if ((System.Object)term.Field() == (System.Object)field)
                    {
                        System.String termtext = term.Text().Trim();

                        /// <summary> Java 1.4 level code:
                        /// if (pIntegers.matcher(termtext).matches())
                        /// return IntegerSortedHitQueue.comparator (reader, enumerator, Field);
                        /// else if (pFloats.matcher(termtext).matches())
                        /// return FloatSortedHitQueue.comparator (reader, enumerator, Field);
                        /// </summary>

                        // Java 1.3 level code:
                        try
                        {
                            System.Int32.Parse(termtext);
                            ret = GetInts(reader, field);
                        }
                        catch (System.FormatException nfe1)
                        {
                            try
                            {
                                System.Single.Parse(termtext);
                                ret = GetFloats(reader, field);
                            }
                            catch (System.FormatException nfe2)
                            {
                                ret = GetStringIndex(reader, field);
                            }
                        }
                        if (ret != null)
                        {
                            Store(reader, field, SortField.AUTO, ret);
                        }
                    }
                    else
                    {
                        throw new System.SystemException("Field \"" + field + "\" does not appear to be indexed");
                    }
                }
                finally
                {
                    enumerator.Close();
                }
            }
            return(ret);
        }
Пример #4
0
 public override System.String ToString(System.String field)
 {
     if (term.Field().Equals(field))
     {
         return(term.Text());
     }
     else
     {
         return(term.ToString());
     }
 }
		protected internal override bool TermCompare(Term term)
		{
			if ((System.Object) field == (System.Object) term.Field())
			{
				System.String searchText = term.Text();
				if (searchText.StartsWith(pre))
				{
					return WildcardEquals(text, 0, searchText, preLen);
				}
			}
			endEnum = true;
			return false;
		}
Пример #6
0
 protected internal override bool TermCompare(Term term)
 {
     if ((System.Object)field == (System.Object)term.Field())
     {
         System.String searchText = term.Text();
         if (searchText.StartsWith(pre))
         {
             return(WildcardEquals(text, 0, searchText, preLen));
         }
     }
     endEnum = true;
     return(false);
 }
Пример #7
0
 // inherit javadocs
 public virtual float[] GetFloats(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field)
 {
     field = String.Intern(field);
     System.Object ret = Lookup(reader, field, SortField.FLOAT);
     if (ret == null)
     {
         float[] retArray = new float[reader.MaxDoc()];
         if (retArray.Length > 0)
         {
             TermDocs termDocs = reader.TermDocs();
             TermEnum termEnum = reader.Terms(new Term(field, ""));
             try
             {
                 if (termEnum.Term() == null)
                 {
                     throw new System.SystemException("no terms in Field " + field);
                 }
                 do
                 {
                     Term term = termEnum.Term();
                     if ((System.Object)term.Field() != (System.Object)field)
                     {
                         break;
                     }
                     float termval;
                     try
                     {
                         termval = SupportClass.Single.Parse(term.Text());
                     }
                     catch (Exception e)
                     {
                         termval = 0;
                     }
                     termDocs.Seek(termEnum);
                     while (termDocs.Next())
                     {
                         retArray[termDocs.Doc()] = termval;
                     }
                 }while (termEnum.Next());
             }
             finally
             {
                 termDocs.Close();
                 termEnum.Close();
             }
         }
         Store(reader, field, SortField.FLOAT, retArray);
         return(retArray);
     }
     return((float[])ret);
 }
Пример #8
0
 /// <summary>The termCompare method in FuzzyTermEnum uses Levenshtein distance to
 /// calculate the distance between the given term and the comparing term.
 /// </summary>
 protected internal override bool TermCompare(Term term)
 {
     System.String termText = term.Text();
     if ((System.Object)field == (System.Object)term.Field() && termText.StartsWith(prefix))
     {
         System.String target    = termText.Substring(prefixLength);
         int           targetlen = target.Length;
         int           dist      = EditDistance(text, target, textlen, targetlen);
         distance = 1 - ((double)dist / (double)System.Math.Min(textlen, targetlen));
         return(distance > minimumSimilarity);
     }
     endEnum = true;
     return(false);
 }
		/// <summary> Creates a new <code>WildcardTermEnum</code>.  Passing in a
		/// {@link Monodoc.Lucene.Net.Index.Term Term} that does not contain a
		/// <code>WILDCARD_CHAR</code> will cause an exception to be thrown.
		/// </summary>
		public WildcardTermEnum(Monodoc.Lucene.Net.Index.IndexReader reader, Term term):base()
		{
			searchTerm = term;
			field = searchTerm.Field();
			text = searchTerm.Text();
			
			int sidx = text.IndexOf((System.Char) WILDCARD_STRING);
			int cidx = text.IndexOf((System.Char) WILDCARD_CHAR);
			int idx = sidx;
			if (idx == - 1)
			{
				idx = cidx;
			}
			else if (cidx >= 0)
			{
				idx = System.Math.Min(idx, cidx);
			}
			
			pre = searchTerm.Text().Substring(0, (idx) - (0));
			preLen = pre.Length;
			text = text.Substring(preLen);
			SetEnum(reader.Terms(new Term(searchTerm.Field(), pre)));
		}
Пример #10
0
        /// <summary> Creates a new <code>WildcardTermEnum</code>.  Passing in a
        /// {@link Monodoc.Lucene.Net.Index.Term Term} that does not contain a
        /// <code>WILDCARD_CHAR</code> will cause an exception to be thrown.
        /// </summary>
        public WildcardTermEnum(Monodoc.Lucene.Net.Index.IndexReader reader, Term term) : base()
        {
            searchTerm = term;
            field      = searchTerm.Field();
            text       = searchTerm.Text();

            int sidx = text.IndexOf((System.Char)WILDCARD_STRING);
            int cidx = text.IndexOf((System.Char)WILDCARD_CHAR);
            int idx  = sidx;

            if (idx == -1)
            {
                idx = cidx;
            }
            else if (cidx >= 0)
            {
                idx = System.Math.Min(idx, cidx);
            }

            pre    = searchTerm.Text().Substring(0, (idx) - (0));
            preLen = pre.Length;
            text   = text.Substring(preLen);
            SetEnum(reader.Terms(new Term(searchTerm.Field(), pre)));
        }
Пример #11
0
        /// <summary> Create a new FuzzyQuery that will match terms with a similarity 
        /// of at least <code>minimumSimilarity</code> to <code>term</code>.
        /// If a <code>prefixLength</code> &gt; 0 is specified, a common prefix
        /// of that length is also required.
        /// 
        /// </summary>
        /// <param name="term">the term to search for
        /// </param>
        /// <param name="minimumSimilarity">a value between 0 and 1 to set the required similarity
        /// between the query term and the matching terms. For example, for a
        /// <code>minimumSimilarity</code> of <code>0.5</code> a term of the same length
        /// as the query term is considered similar to the query term if the edit distance
        /// between both terms is less than <code>length(term)*0.5</code>
        /// </param>
        /// <param name="prefixLength">length of common (non-fuzzy) prefix
        /// </param>
        /// <throws>  IllegalArgumentException if minimumSimilarity is &gt; 1 or &lt; 0 </throws>
        /// <summary> or if prefixLength &lt; 0 or &gt; <code>term.text().length()</code>.
        /// </summary>
        public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength):base(term)
        {
			
            if (minimumSimilarity > 1.0f)
                throw new System.ArgumentException("minimumSimilarity > 1");
            else if (minimumSimilarity < 0.0f)
                throw new System.ArgumentException("minimumSimilarity < 0");
            this.minimumSimilarity = minimumSimilarity;
			
            if (prefixLength < 0)
                throw new System.ArgumentException("prefixLength < 0");
            else if (prefixLength >= term.Text().Length)
                throw new System.ArgumentException("prefixLength >= term.text().length()");
            this.prefixLength = prefixLength;
        }
Пример #12
0
 /// <summary> Constructor for enumeration of all terms from specified <code>reader</code> which share a prefix of
 /// length <code>prefixLength</code> with <code>term</code> and which have a fuzzy similarity &gt;
 /// <code>minSimilarity</code>.
 ///
 /// </summary>
 /// <param name="reader">Delivers terms.
 /// </param>
 /// <param name="term">Pattern term.
 /// </param>
 /// <param name="minSimilarity">Minimum required similarity for terms from the reader. Default value is 0.5f.
 /// </param>
 /// <param name="prefixLength">Length of required common prefix. Default value is 0.
 /// </param>
 /// <throws>  IOException </throws>
 public FuzzyTermEnum(Monodoc.Lucene.Net.Index.IndexReader reader, Term term, float minSimilarity, int prefixLength) : base()
 {
     InitBlock();
     minimumSimilarity = minSimilarity;
     scale_factor      = 1.0f / (1.0f - minimumSimilarity);
     searchTerm        = term;
     field             = searchTerm.Field();
     text    = searchTerm.Text();
     textlen = text.Length;
     if (prefixLength > 0 && prefixLength < textlen)
     {
         this.prefixLength = prefixLength;
         prefix            = text.Substring(0, (prefixLength) - (0));
         text    = text.Substring(prefixLength);
         textlen = text.Length;
     }
     SetEnum(reader.Terms(new Term(searchTerm.Field(), prefix)));
 }
Пример #13
0
        /// <summary>Prints a user-readable version of this query. </summary>
        public override System.String ToString(System.String field)
        {
            System.Text.StringBuilder buffer = new System.Text.StringBuilder();
            if (!term.Field().Equals(field))
            {
                buffer.Append(term.Field());
                buffer.Append(":");
            }
            buffer.Append(term.Text());
            if (GetBoost() != 1.0f)
            {
                System.Globalization.NumberFormatInfo nfi = new System.Globalization.CultureInfo("en-US", false).NumberFormat;
                nfi.NumberDecimalDigits = 1;

                buffer.Append("^");
                buffer.Append(GetBoost().ToString("N", nfi));
            }
            return(buffer.ToString());
        }
Пример #14
0
 // inherit javadocs
 public virtual System.IComparable[] GetCustom(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field, SortComparator comparator)
 {
     field = String.Intern(field);
     System.Object ret = Lookup(reader, field, comparator);
     if (ret == null)
     {
         System.IComparable[] retArray = new System.IComparable[reader.MaxDoc()];
         if (retArray.Length > 0)
         {
             TermDocs termDocs = reader.TermDocs();
             TermEnum termEnum = reader.Terms(new Term(field, ""));
             try
             {
                 if (termEnum.Term() == null)
                 {
                     throw new System.SystemException("no terms in Field " + field);
                 }
                 do
                 {
                     Term term = termEnum.Term();
                     if ((System.Object)term.Field() != (System.Object)field)
                     {
                         break;
                     }
                     System.IComparable termval = comparator.GetComparable(term.Text());
                     termDocs.Seek(termEnum);
                     while (termDocs.Next())
                     {
                         retArray[termDocs.Doc()] = termval;
                     }
                 }while (termEnum.Next());
             }
             finally
             {
                 termDocs.Close();
                 termEnum.Close();
             }
         }
         Store(reader, field, SortField.CUSTOM, retArray);
         return(retArray);
     }
     return((System.IComparable[])ret);
 }
Пример #15
0
        /// <summary> Create a new FuzzyQuery that will match terms with a similarity
        /// of at least <code>minimumSimilarity</code> to <code>term</code>.
        /// If a <code>prefixLength</code> &gt; 0 is specified, a common prefix
        /// of that length is also required.
        ///
        /// </summary>
        /// <param name="term">the term to search for
        /// </param>
        /// <param name="minimumSimilarity">a value between 0 and 1 to set the required similarity
        /// between the query term and the matching terms. For example, for a
        /// <code>minimumSimilarity</code> of <code>0.5</code> a term of the same length
        /// as the query term is considered similar to the query term if the edit distance
        /// between both terms is less than <code>length(term)*0.5</code>
        /// </param>
        /// <param name="prefixLength">length of common (non-fuzzy) prefix
        /// </param>
        /// <throws>  IllegalArgumentException if minimumSimilarity is &gt; 1 or &lt; 0 </throws>
        /// <summary> or if prefixLength &lt; 0 or &gt; <code>term.text().length()</code>.
        /// </summary>
        public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength) : base(term)
        {
            if (minimumSimilarity > 1.0f)
            {
                throw new System.ArgumentException("minimumSimilarity > 1");
            }
            else if (minimumSimilarity < 0.0f)
            {
                throw new System.ArgumentException("minimumSimilarity < 0");
            }
            this.minimumSimilarity = minimumSimilarity;

            if (prefixLength < 0)
            {
                throw new System.ArgumentException("prefixLength < 0");
            }
            else if (prefixLength >= term.Text().Length)
            {
                throw new System.ArgumentException("prefixLength >= term.text().length()");
            }
            this.prefixLength = prefixLength;
        }
Пример #16
0
 /// <summary> Constructor for enumeration of all terms from specified <code>reader</code> which share a prefix of
 /// length <code>prefixLength</code> with <code>term</code> and which have a fuzzy similarity &gt;
 /// <code>minSimilarity</code>. 
 /// 
 /// </summary>
 /// <param name="reader">Delivers terms.
 /// </param>
 /// <param name="term">Pattern term.
 /// </param>
 /// <param name="minSimilarity">Minimum required similarity for terms from the reader. Default value is 0.5f.
 /// </param>
 /// <param name="prefixLength">Length of required common prefix. Default value is 0.
 /// </param>
 /// <throws>  IOException </throws>
 public FuzzyTermEnum(Monodoc.Lucene.Net.Index.IndexReader reader, Term term, float minSimilarity, int prefixLength):base()
 {
     InitBlock();
     minimumSimilarity = minSimilarity;
     scale_factor = 1.0f / (1.0f - minimumSimilarity);
     searchTerm = term;
     field = searchTerm.Field();
     text = searchTerm.Text();
     textlen = text.Length;
     if (prefixLength > 0 && prefixLength < textlen)
     {
         this.prefixLength = prefixLength;
         prefix = text.Substring(0, (prefixLength) - (0));
         text = text.Substring(prefixLength);
         textlen = text.Length;
     }
     SetEnum(reader.Terms(new Term(searchTerm.Field(), prefix)));
 }
Пример #17
0
 /// <summary>The termCompare method in FuzzyTermEnum uses Levenshtein distance to 
 /// calculate the distance between the given term and the comparing term. 
 /// </summary>
 protected internal override bool TermCompare(Term term)
 {
     System.String termText = term.Text();
     if ((System.Object) field == (System.Object) term.Field() && termText.StartsWith(prefix))
     {
         System.String target = termText.Substring(prefixLength);
         int targetlen = target.Length;
         int dist = EditDistance(text, target, textlen, targetlen);
         distance = 1 - ((double) dist / (double) System.Math.Min(textlen, targetlen));
         return (distance > minimumSimilarity);
     }
     endEnum = true;
     return false;
 }
        public virtual Explanation Explain(Monodoc.Lucene.Net.Index.IndexReader reader, int doc)
        {
            Explanation result = new Explanation();

            result.SetDescription("weight(" + Query + " in " + doc + "), product of:");
            System.String field = ((SpanQuery)Query).GetField();

            System.Text.StringBuilder      docFreqs = new System.Text.StringBuilder();
            System.Collections.IEnumerator i        = terms.GetEnumerator();
            while (i.MoveNext())
            {
                Term term = (Term)i.Current;
                docFreqs.Append(term.Text());
                docFreqs.Append("=");
                docFreqs.Append(searcher.DocFreq(term));

                if (i.MoveNext())
                {
                    docFreqs.Append(" ");
                }
            }

            Explanation idfExpl = new Explanation(idf, "idf(" + field + ": " + docFreqs + ")");

            // explain query weight
            Explanation queryExpl = new Explanation();

            queryExpl.SetDescription("queryWeight(" + Query + "), product of:");

            Explanation boostExpl = new Explanation(Query.GetBoost(), "boost");

            if (Query.GetBoost() != 1.0f)
            {
                queryExpl.AddDetail(boostExpl);
            }
            queryExpl.AddDetail(idfExpl);

            Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");

            queryExpl.AddDetail(queryNormExpl);

            queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

            result.AddDetail(queryExpl);

            // explain Field weight
            Explanation fieldExpl = new Explanation();

            fieldExpl.SetDescription("fieldWeight(" + field + ":" + query.ToString(field) + " in " + doc + "), product of:");

            Explanation tfExpl = Scorer(reader).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]) : 0.0f;

            fieldNormExpl.SetValue(fieldNorm);
            fieldNormExpl.SetDescription("fieldNorm(Field=" + field + ", doc=" + doc + ")");
            fieldExpl.AddDetail(fieldNormExpl);

            fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

            result.AddDetail(fieldExpl);

            // combine them
            result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

            if (queryExpl.GetValue() == 1.0f)
            {
                return(fieldExpl);
            }

            return(result);
        }
Пример #19
0
            public virtual Explanation Explain(Monodoc.Lucene.Net.Index.IndexReader reader, int doc)
            {
                Explanation result = new Explanation();

                result.SetDescription("weight(" + Query + " in " + doc + "), product of:");

                System.Text.StringBuilder docFreqs = new System.Text.StringBuilder();
                System.Text.StringBuilder query    = new System.Text.StringBuilder();
                query.Append('\"');
                for (int i = 0; i < Enclosing_Instance.terms.Count; i++)
                {
                    if (i != 0)
                    {
                        docFreqs.Append(" ");
                        query.Append(" ");
                    }

                    Term term = (Term)Enclosing_Instance.terms[i];

                    docFreqs.Append(term.Text());
                    docFreqs.Append("=");
                    docFreqs.Append(searcher.DocFreq(term));

                    query.Append(term.Text());
                }
                query.Append('\"');

                Explanation idfExpl = new Explanation(idf, "idf(" + Enclosing_Instance.field + ": " + docFreqs + ")");

                // explain query weight
                Explanation queryExpl = new Explanation();

                queryExpl.SetDescription("queryWeight(" + Query + "), product of:");

                Explanation boostExpl = new Explanation(Enclosing_Instance.GetBoost(), "boost");

                if (Enclosing_Instance.GetBoost() != 1.0f)
                {
                    queryExpl.AddDetail(boostExpl);
                }
                queryExpl.AddDetail(idfExpl);

                Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");

                queryExpl.AddDetail(queryNormExpl);

                queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

                result.AddDetail(queryExpl);

                // explain Field weight
                Explanation fieldExpl = new Explanation();

                fieldExpl.SetDescription("fieldWeight(" + Enclosing_Instance.field + ":" + query + " in " + doc + "), product of:");

                Explanation tfExpl = Scorer(reader).Explain(doc);

                fieldExpl.AddDetail(tfExpl);
                fieldExpl.AddDetail(idfExpl);

                Explanation fieldNormExpl = new Explanation();

                byte[] fieldNorms = reader.Norms(Enclosing_Instance.field);
                float  fieldNorm  = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]) : 0.0f;

                fieldNormExpl.SetValue(fieldNorm);
                fieldNormExpl.SetDescription("fieldNorm(Field=" + Enclosing_Instance.field + ", doc=" + doc + ")");
                fieldExpl.AddDetail(fieldNormExpl);

                fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

                result.AddDetail(fieldExpl);

                // combine them
                result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

                if (queryExpl.GetValue() == 1.0f)
                {
                    return(fieldExpl);
                }

                return(result);
            }
Пример #20
0
        // inherit javadocs
        public virtual StringIndex GetStringIndex(Monodoc.Lucene.Net.Index.IndexReader reader, System.String field)
        {
            field = String.Intern(field);
            System.Object ret = Lookup(reader, field, Monodoc.Lucene.Net.Search.FieldCache_Fields.STRING_INDEX);
            if (ret == null)
            {
                int[]           retArray = new int[reader.MaxDoc()];
                System.String[] mterms   = new System.String[reader.MaxDoc() + 1];
                if (retArray.Length > 0)
                {
                    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
                    {
                        if (termEnum.Term() == null)
                        {
                            throw new System.SystemException("no terms in Field " + field);
                        }
                        do
                        {
                            Term term = termEnum.Term();
                            if ((System.Object)term.Field() != (System.Object)field)
                            {
                                break;
                            }

                            // store term text
                            // we expect that there is at most one term per document
                            if (t >= mterms.Length)
                            {
                                throw new System.SystemException("there are more terms than documents in Field \"" + field + "\"");
                            }
                            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);
                Store(reader, field, Monodoc.Lucene.Net.Search.FieldCache_Fields.STRING_INDEX, value_Renamed);
                return(value_Renamed);
            }
            return((StringIndex)ret);
        }