Beispiel #1
0
 /// <summary> Initializes the token stream with the supplied <code>float</code> value.</summary>
 /// <param name="value">the value, for which this TokenStream should enumerate tokens.
 /// </param>
 /// <returns> this instance, because of this you can use it the following way:
 /// <code>new Field(name, new NumericTokenStream(precisionStep).SetFloatValue(value))</code>
 /// </returns>
 public NumericTokenStream SetFloatValue(float value_Renamed)
 {
     this.value_Renamed = (long)NumericUtils.FloatToSortableInt(value_Renamed);
     valSize            = 32;
     shift = 0;
     return(this);
 }
Beispiel #2
0
 /// <summary> Initializes the token stream with the supplied <code>double</code> value.</summary>
 /// <param name="value">the value, for which this TokenStream should enumerate tokens.
 /// </param>
 /// <returns> this instance, because of this you can use it the following way:
 /// <code>new Field(name, new NumericTokenStream(precisionStep).SetDoubleValue(value))</code>
 /// </returns>
 public NumericTokenStream SetDoubleValue(double value_Renamed)
 {
     this.value_Renamed = NumericUtils.DoubleToSortableLong(value_Renamed);
     valSize            = 64;
     shift = 0;
     return(this);
 }
Beispiel #3
0
        public virtual double ParseDouble(System.String val)
        {
            int shift = val[0] - NumericUtils.SHIFT_START_LONG;

            if (shift > 0 && shift <= 63)
            {
                throw new FieldCacheImpl.StopFillCacheException();
            }
            return(NumericUtils.SortableLongToDouble(NumericUtils.PrefixCodedToLong(val)));
        }
Beispiel #4
0
        public virtual float ParseFloat(System.String val)
        {
            int shift = val[0] - NumericUtils.SHIFT_START_INT;

            if (shift > 0 && shift <= 31)
            {
                throw new FieldCacheImpl.StopFillCacheException();
            }
            return(NumericUtils.SortableIntToFloat(NumericUtils.PrefixCodedToInt(val)));
        }
            public override DocIdSet GetDocIdSet(IndexReader reader)
            {
                // we transform the floating point numbers to sortable integers
                // using NumericUtils to easier find the next bigger/lower value
                double inclusiveLowerPoint;
                double inclusiveUpperPoint;

                if (lowerVal != null)
                {
                    double f = System.Convert.ToDouble(((System.ValueType)lowerVal));
                    if (!includeUpper && f > 0.0 && System.Double.IsInfinity(f))
                    {
                        return(DocIdSet.EMPTY_DOCIDSET);
                    }
                    long i = NumericUtils.DoubleToSortableLong(f);
                    inclusiveLowerPoint = NumericUtils.SortableLongToDouble(includeLower?i:(i + 1L));
                }
                else
                {
                    inclusiveLowerPoint = System.Double.NegativeInfinity;
                }
                if (upperVal != null)
                {
                    double f = System.Convert.ToDouble(((System.ValueType)upperVal));
                    if (!includeUpper && f < 0.0 && System.Double.IsInfinity(f))
                    {
                        return(DocIdSet.EMPTY_DOCIDSET);
                    }
                    long i = NumericUtils.DoubleToSortableLong(f);
                    inclusiveUpperPoint = NumericUtils.SortableLongToDouble(includeUpper?i:(i - 1L));
                }
                else
                {
                    inclusiveUpperPoint = System.Double.PositiveInfinity;
                }

                if (inclusiveLowerPoint > inclusiveUpperPoint)
                {
                    return(DocIdSet.EMPTY_DOCIDSET);
                }

                double[] values = Mono.Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetDoubles(reader, field, (Mono.Lucene.Net.Search.DoubleParser)parser);
                // we only request the usage of termDocs, if the range contains 0
                return(new AnonymousClassFieldCacheDocIdSet(values, inclusiveLowerPoint, inclusiveUpperPoint, this, reader, (inclusiveLowerPoint <= 0.0 && inclusiveUpperPoint >= 0.0)));
            }
Beispiel #6
0
        // @Override
        public override bool IncrementToken()
        {
            if (valSize == 0)
            {
                throw new System.SystemException("call set???Value() before usage");
            }
            if (shift >= valSize)
            {
                return(false);
            }

            ClearAttributes();
            char[] buffer;
            switch (valSize)
            {
            case 64:
                buffer = termAtt.ResizeTermBuffer(NumericUtils.BUF_SIZE_LONG);
                termAtt.SetTermLength(NumericUtils.LongToPrefixCoded(value_Renamed, shift, buffer));
                break;


            case 32:
                buffer = termAtt.ResizeTermBuffer(NumericUtils.BUF_SIZE_INT);
                termAtt.SetTermLength(NumericUtils.IntToPrefixCoded((int)value_Renamed, shift, buffer));
                break;


            default:
                // should not happen
                throw new System.ArgumentException("valSize must be 32 or 64");
            }

            typeAtt.SetType((shift == 0)?TOKEN_TYPE_FULL_PREC:TOKEN_TYPE_LOWER_PREC);
            posIncrAtt.SetPositionIncrement((shift == 0)?1:0);
            shift += precisionStep;
            return(true);
        }
Beispiel #7
0
            internal NumericRangeTermEnum(NumericRangeQuery enclosingInstance, IndexReader reader)
            {
                InitBlock(enclosingInstance);
                this.reader = reader;

                switch (Enclosing_Instance.valSize)
                {
                case 64:  {
                    // lower
                    long minBound = System.Int64.MinValue;
                    if (Enclosing_Instance.min is System.Int64)
                    {
                        minBound = System.Convert.ToInt64(Enclosing_Instance.min);
                    }
                    else if (Enclosing_Instance.min is System.Double)
                    {
                        minBound = NumericUtils.DoubleToSortableLong(System.Convert.ToDouble(Enclosing_Instance.min));
                    }
                    if (!Enclosing_Instance.minInclusive && Enclosing_Instance.min != null)
                    {
                        if (minBound == System.Int64.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    long maxBound = System.Int64.MaxValue;
                    if (Enclosing_Instance.max is System.Int64)
                    {
                        maxBound = System.Convert.ToInt64(Enclosing_Instance.max);
                    }
                    else if (Enclosing_Instance.max is System.Double)
                    {
                        maxBound = NumericUtils.DoubleToSortableLong(System.Convert.ToDouble(Enclosing_Instance.max));
                    }
                    if (!Enclosing_Instance.maxInclusive && Enclosing_Instance.max != null)
                    {
                        if (maxBound == System.Int64.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitLongRange(new AnonymousClassLongRangeBuilder(this), Enclosing_Instance.precisionStep, minBound, maxBound);
                    break;
                }


                case 32:  {
                    // lower
                    int minBound = System.Int32.MinValue;
                    if (Enclosing_Instance.min is System.Int32)
                    {
                        minBound = System.Convert.ToInt32(Enclosing_Instance.min);
                    }
                    else if (Enclosing_Instance.min is System.Single)
                    {
                        minBound = NumericUtils.FloatToSortableInt(System.Convert.ToSingle(Enclosing_Instance.min));
                    }
                    if (!Enclosing_Instance.minInclusive && Enclosing_Instance.min != null)
                    {
                        if (minBound == System.Int32.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    int maxBound = System.Int32.MaxValue;
                    if (Enclosing_Instance.max is System.Int32)
                    {
                        maxBound = System.Convert.ToInt32(Enclosing_Instance.max);
                    }
                    else if (Enclosing_Instance.max is System.Single)
                    {
                        maxBound = NumericUtils.FloatToSortableInt(System.Convert.ToSingle(Enclosing_Instance.max));
                    }
                    if (!Enclosing_Instance.maxInclusive && Enclosing_Instance.max != null)
                    {
                        if (maxBound == System.Int32.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitIntRange(new AnonymousClassIntRangeBuilder(this), Enclosing_Instance.precisionStep, minBound, maxBound);
                    break;
                }


                default:
                    // should never happen
                    throw new System.ArgumentException("valSize must be 32 or 64");
                }

                // seek to first term
                Next();
            }