Пример #1
0
 /// <summary> Initializes the token stream with the supplied <c>double</c> value.</summary>
 /// <param name="value_Renamed">the value, for which this TokenStream should enumerate tokens.
 /// </param>
 /// <returns> this instance, because of this you can use it the following way:
 /// <c>new Field(name, new NumericTokenStream(precisionStep).SetDoubleValue(value))</c>
 /// </returns>
 public NumericTokenStream SetDoubleValue(double value_Renamed)
 {
     this.value_Renamed = NumericUtils.DoubleToSortableLong(value_Renamed);
     valSize            = 64;
     shift = 0;
     return(this);
 }
Пример #2
0
            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 = (double)lowerVal;
                    if (!includeUpper && f > 0.0 && double.IsInfinity(f))
                    {
                        return(DocIdSet.EMPTY_DOCIDSET);
                    }
                    long i = NumericUtils.DoubleToSortableLong(f);
                    inclusiveLowerPoint = NumericUtils.SortableLongToDouble(includeLower ? i : (i + 1L));
                }
                else
                {
                    inclusiveLowerPoint = double.NegativeInfinity;
                }
                if (upperVal != null)
                {
                    double f = (double)upperVal;
                    if (!includeUpper && f < 0.0 && double.IsInfinity(f))
                    {
                        return(DocIdSet.EMPTY_DOCIDSET);
                    }
                    long i = NumericUtils.DoubleToSortableLong(f);
                    inclusiveUpperPoint = NumericUtils.SortableLongToDouble(includeUpper ? i : (i - 1L));
                }
                else
                {
                    inclusiveUpperPoint = double.PositiveInfinity;
                }

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

                double[] values = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetDoubles(reader, field, (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)));
            }
Пример #3
0
 internal LongRange ToLongRange()
 {
     return(new LongRange(Label, NumericUtils.DoubleToSortableLong(minIncl), true, NumericUtils.DoubleToSortableLong(maxIncl), true));
 }
Пример #4
0
            internal NumericRangeTermEnum(NumericRangeQuery <T> enclosingInstance, IndexReader reader)
            {
                InitBlock(enclosingInstance);
                this.reader = reader;

                Type rangeType = Nullable.GetUnderlyingType(typeof(T?));

                switch (Enclosing_Instance.valSize)
                {
                case 64:  {
                    // lower
                    long minBound = System.Int64.MinValue;
                    if (rangeType == typeof(System.Int64))
                    {
                        // added in these checks to emulate java.  passing null give it no type (in old code),
                        // but .net can identifies it with generics and sets the bounds to 0, causing tests to fail
                        if (Enclosing_Instance.min != null)
                        {
                            minBound = System.Convert.ToInt64(Enclosing_Instance.min);
                        }
                    }
                    else if (rangeType == typeof(System.Double))
                    {
                        if (Enclosing_Instance.min != null)
                        {
                            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 (rangeType == typeof(System.Int64))
                    {
                        if (Enclosing_Instance.max != null)
                        {
                            maxBound = System.Convert.ToInt64(Enclosing_Instance.max);
                        }
                    }
                    else if (rangeType == typeof(System.Double))
                    {
                        if (Enclosing_Instance.max != null)
                        {
                            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 (rangeType == typeof(System.Int32))
                    {
                        if (Enclosing_Instance.min != null)
                        {
                            minBound = System.Convert.ToInt32(Enclosing_Instance.min);
                        }
                    }
                    else if (rangeType == typeof(System.Single))
                    {
                        if (Enclosing_Instance.min != null)
                        {
                            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 (rangeType == typeof(System.Int32))
                    {
                        if (Enclosing_Instance.max != null)
                        {
                            maxBound = System.Convert.ToInt32(Enclosing_Instance.max);
                        }
                    }
                    else if (rangeType == typeof(System.Single))
                    {
                        if (Enclosing_Instance.max != null)
                        {
                            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();
            }
Пример #5
0
            internal NumericRangeTermsEnum(NumericRangeQuery <T> outerInstance, TermsEnum tenum)
                : base(tenum)
            {
                this.OuterInstance = outerInstance;
                switch (OuterInstance.DataType)
                {
                case NumericType.LONG:
                case NumericType.DOUBLE:
                {
                    // lower
                    long minBound;
                    if (OuterInstance.DataType == NumericType.LONG)
                    {
                        minBound = (OuterInstance.min == null) ? long.MinValue : Convert.ToInt64(OuterInstance.min.Value);
                    }
                    else
                    {
                        Debug.Assert(OuterInstance.DataType == NumericType.DOUBLE);
                        minBound = (OuterInstance.min == null) ? LONG_NEGATIVE_INFINITY : NumericUtils.DoubleToSortableLong(Convert.ToDouble(OuterInstance.min.Value));
                    }
                    if (!OuterInstance.MinInclusive && OuterInstance.min != null)
                    {
                        if (minBound == long.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    long maxBound;
                    if (OuterInstance.DataType == NumericType.LONG)
                    {
                        maxBound = (OuterInstance.max == null) ? long.MaxValue : Convert.ToInt64(OuterInstance.max);
                    }
                    else
                    {
                        Debug.Assert(OuterInstance.DataType == NumericType.DOUBLE);
                        maxBound = (OuterInstance.max == null) ? LONG_POSITIVE_INFINITY : NumericUtils.DoubleToSortableLong(Convert.ToDouble(OuterInstance.max));
                    }
                    if (!OuterInstance.MaxInclusive && OuterInstance.max != null)
                    {
                        if (maxBound == long.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitLongRange(new LongRangeBuilderAnonymousInnerClassHelper(this), OuterInstance.precisionStep, minBound, maxBound);
                    break;
                }

                case NumericType.INT:
                case NumericType.FLOAT:
                {
                    // lower
                    int minBound;
                    if (OuterInstance.DataType == NumericType.INT)
                    {
                        minBound = (OuterInstance.min == null) ? int.MinValue : Convert.ToInt32(OuterInstance.min);
                    }
                    else
                    {
                        Debug.Assert(OuterInstance.DataType == NumericType.FLOAT);
                        minBound = (OuterInstance.min == null) ? INT_NEGATIVE_INFINITY : NumericUtils.FloatToSortableInt(Convert.ToSingle(OuterInstance.min));
                    }
                    if (!OuterInstance.MinInclusive && OuterInstance.min != null)
                    {
                        if (minBound == int.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    int maxBound;
                    if (OuterInstance.DataType == NumericType.INT)
                    {
                        maxBound = (OuterInstance.max == null) ? int.MaxValue : Convert.ToInt32(OuterInstance.max);
                    }
                    else
                    {
                        Debug.Assert(OuterInstance.DataType == NumericType.FLOAT);
                        maxBound = (OuterInstance.max == null) ? INT_POSITIVE_INFINITY : NumericUtils.FloatToSortableInt(Convert.ToSingle(OuterInstance.max));
                    }
                    if (!OuterInstance.MaxInclusive && OuterInstance.max != null)
                    {
                        if (maxBound == int.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitIntRange(new IntRangeBuilderAnonymousInnerClassHelper(this), OuterInstance.precisionStep, minBound, maxBound);
                    break;
                }

                default:
                    // should never happen
                    throw new System.ArgumentException("Invalid NumericType");
                }

                TermComp = Comparator;
            }
Пример #6
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)
 {
     NumericAtt.Init(NumericUtils.DoubleToSortableLong(value), ValSize = 64, PrecisionStep_Renamed, -PrecisionStep_Renamed);
     return(this);
 }
Пример #7
0
        private void Count(ValueSource valueSource, IEnumerable <MatchingDocs> matchingDocs)
        {
            DoubleRange[] ranges = (DoubleRange[])this.Ranges;

            LongRange[] longRanges = new LongRange[ranges.Length];
            for (int i = 0; i < ranges.Length; i++)
            {
                DoubleRange range = ranges[i];
                longRanges[i] = new LongRange(range.Label, NumericUtils.DoubleToSortableLong(range.minIncl), true, NumericUtils.DoubleToSortableLong(range.maxIncl), true);
            }

            LongRangeCounter counter = new LongRangeCounter(longRanges);

            int missingCount = 0;

            foreach (MatchingDocs hits in matchingDocs)
            {
                FunctionValues fv = valueSource.GetValues(new Dictionary <string, object>(), hits.context);

                TotCount += hits.totalHits;
                Bits bits;
                if (FastMatchFilter != null)
                {
                    DocIdSet dis = FastMatchFilter.GetDocIdSet(hits.context, null);
                    if (dis == null)
                    {
                        // No documents match
                        continue;
                    }
                    bits = dis.GetBits();
                    if (bits == null)
                    {
                        throw new System.ArgumentException("fastMatchFilter does not implement DocIdSet.bits");
                    }
                }
                else
                {
                    bits = null;
                }

                DocIdSetIterator docs = hits.bits.GetIterator();

                int doc;
                while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
                {
                    if (bits != null && bits.Get(doc) == false)
                    {
                        doc++;
                        continue;
                    }
                    // Skip missing docs:
                    if (fv.Exists(doc))
                    {
                        counter.add(NumericUtils.DoubleToSortableLong(fv.DoubleVal(doc)));
                    }
                    else
                    {
                        missingCount++;
                    }
                }
            }

            missingCount += counter.fillCounts(Counts);
            TotCount     -= missingCount;
        }