Ejemplo n.º 1
0
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                Entry 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 ne)
                    {
                        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 stop)
                {
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                if (retArray == null)
                {
                    // no values
                    retArray = new double[reader.MaxDoc()];
                }
                return(retArray);
            }
Ejemplo n.º 2
0
 // inherit javadocs
 public virtual float[] GetFloats(IndexReader reader, System.String field, FloatParser parser)
 {
     field = String.Intern(field);
     System.Object ret = Lookup(reader, field, parser);
     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 (term.Field() != 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, parser, retArray);
         return(retArray);
     }
     return((float[])ret);
 }
Ejemplo n.º 3
0
 // inherit javadocs
 public virtual System.IComparable[] GetCustom(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 (term.Field() != 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, comparator, retArray);
         return(retArray);
     }
     return((System.IComparable[])ret);
 }
Ejemplo n.º 4
0
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                Entry entry = (Entry)entryKey;

                System.String field  = entry.field;
                ShortParser   parser = (ShortParser)entry.custom;

                if (parser == null)
                {
                    return(wrapper.GetShorts(reader, field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_SHORT_PARSER));
                }
                short[]  retArray = new short[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;
                        }
                        short termval = parser.ParseShort(term.Text());
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc()] = termval;
                        }
                    }while (termEnum.Next());
                }
                catch (StopFillCacheException stop)
                {
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                return(retArray);
            }
Ejemplo n.º 5
0
 // inherit javadocs
 public virtual System.String[] GetStrings(IndexReader reader, System.String field)
 {
     field = String.Intern(field);
     System.Object ret = Lookup(reader, field, SortField.STRING, null);
     if (ret == null)
     {
         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 || term.Field() != 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();
         }
         Store(reader, field, SortField.STRING, null, retArray);
         return(retArray);
     }
     return((System.String[])ret);
 }
Ejemplo n.º 6
0
 // inherit javadocs
 public virtual int[] GetInts(IndexReader reader, System.String field, IntParser parser)
 {
     field = String.Intern(field);
     System.Object ret = Lookup(reader, field, parser);
     if (ret == null)
     {
         int[]    retArray = new int[reader.MaxDoc()];
         TermDocs termDocs = reader.TermDocs();
         TermEnum termEnum = reader.Terms(new Term(field, ""));
         try
         {
             do
             {
                 Term term = termEnum.Term();
                 if (term == null || term.Field() != field)
                 {
                     break;
                 }
                 int termval = parser.ParseInt(term.Text());
                 termDocs.Seek(termEnum);
                 while (termDocs.Next())
                 {
                     retArray[termDocs.Doc()] = termval;
                 }
             }while (termEnum.Next());
         }
         finally
         {
             termDocs.Close();
             termEnum.Close();
         }
         Store(reader, field, parser, retArray);
         return(retArray);
     }
     return((int[])ret);
 }
Ejemplo n.º 7
0
 public override int Doc()
 {
     return(termDocs.Doc());
 }
Ejemplo n.º 8
0
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                System.String   field    = StringHelper.Intern((System.String)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 || (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 + "\", but it's impossible to sort on " + "tokenized fields");
                        }
                        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);
            }
Ejemplo n.º 9
0
        // inherit javadocs
        public virtual StringIndex GetStringIndex(IndexReader reader, System.String field)
        {
            field = String.Intern(field);
            System.Object ret = Lookup(reader, field, 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 (term.Field() != 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 + "\", but it's impossible to sort on " + "tokenized fields");
                            }
                            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, Lucene.Net.Search.FieldCache_Fields.STRING_INDEX, value_Renamed);
                return(value_Renamed);
            }
            return((StringIndex)ret);
        }
Ejemplo n.º 10
0
 public override int NextDoc()
 {
     return(doc = termDocs.Next()?termDocs.Doc():NO_MORE_DOCS);
 }
Ejemplo n.º 11
0
        /// <summary> Returns a DocIdSet with documents that should be
        /// permitted in search results.
        /// </summary>
        public override DocIdSet GetDocIdSet(IndexReader reader)
        {
            OpenBitSet bits = new OpenBitSet(reader.MaxDoc());

            TermEnum enumerator = (null != lowerTerm && collator == null ?
                                   reader.Terms(new Term(fieldName, lowerTerm)) :
                                   reader.Terms(new Term(fieldName)));

            try
            {
                if (enumerator.Term() == null)
                {
                    return(bits);
                }

                TermDocs termDocs = reader.TermDocs();
                try
                {
                    if (collator != null)
                    {
                        do
                        {
                            Term term = enumerator.Term();
                            if (term != null && term.Field().Equals(fieldName))
                            {
                                if ((lowerTerm == null ||
                                     (includeLower ? collator.Compare(term.Text(), lowerTerm) >= 0 : collator.Compare(term.Text(), lowerTerm) > 0)) &&
                                    (upperTerm == null ||
                                     (includeUpper ? collator.Compare(term.Text(), upperTerm) <= 0 : collator.Compare(term.Text(), upperTerm) < 0)))
                                {
                                    // term in range, lookup docs
                                    termDocs.Seek(enumerator.Term());
                                    while (termDocs.Next())
                                    {
                                        bits.Set(termDocs.Doc());
                                    }
                                }
                            }
                        }while (enumerator.Next());
                    }
                    else // null collator; using Unicode code point ordering
                    {
                        bool checkLower = false;
                        if (!includeLower) // make adjustments to set to exclusive
                        {
                            checkLower = true;
                        }
                        do
                        {
                            Term term = enumerator.Term();
                            if (term != null && term.Field().Equals(fieldName))
                            {
                                if (!checkLower || null == lowerTerm || String.CompareOrdinal(term.Text(), lowerTerm) > 0)
                                {
                                    checkLower = false;
                                    if (upperTerm != null)
                                    {
                                        int compare = String.CompareOrdinal(upperTerm, term.Text());

                                        /* if beyond the upper term, or is exclusive and
                                         * this is equal to the upper term, break out */
                                        if ((compare < 0) || (!includeUpper && compare == 0))
                                        {
                                            break;
                                        }
                                    }
                                    /* we have a good term, find the docs */

                                    termDocs.Seek(enumerator.Term());
                                    while (termDocs.Next())
                                    {
                                        bits.Set(termDocs.Doc());
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }while (enumerator.Next());
                    }
                }
                finally
                {
                    termDocs.Close();
                }
            }
            finally
            {
                enumerator.Close();
            }

            return(bits);
        }
Ejemplo n.º 12
0
        /// <summary> Returns a BitSet with true for documents which should be
        /// permitted in search results, and false for those that should
        /// not.
        /// </summary>
        public override System.Collections.BitArray Bits(IndexReader reader)
        {
            System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64);
            TermEnum enumerator = (null != lowerTerm ? reader.Terms(new Term(fieldName, lowerTerm)) : reader.Terms(new Term(fieldName, "")));

            try
            {
                if (enumerator.Term() == null)
                {
                    return(bits);
                }

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

                TermDocs termDocs = reader.TermDocs();
                try
                {
                    do
                    {
                        Term term = enumerator.Term();
                        if (term != null && term.Field().Equals(fieldName))
                        {
                            if (!checkLower || null == lowerTerm || String.CompareOrdinal(term.Text(), lowerTerm) > 0)
                            {
                                checkLower = false;
                                if (upperTerm != null)
                                {
                                    int compare = String.CompareOrdinal(upperTerm, term.Text());

                                    /* if beyond the upper term, or is exclusive and
                                     * this is equal to the upper term, break out */
                                    if ((compare < 0) || (!includeUpper && compare == 0))
                                    {
                                        break;
                                    }
                                }
                                /* we have a good term, find the docs */

                                termDocs.Seek(enumerator.Term());
                                while (termDocs.Next())
                                {
                                    bits.Set(termDocs.Doc(), true);
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }while (enumerator.Next());
                }
                finally
                {
                    termDocs.Close();
                }
            }
            finally
            {
                enumerator.Close();
            }

            return(bits);
        }