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)); }
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 = 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))); }
/// <summary>we fake a double test using long2double conversion of NumericUtils </summary> private void TestDoubleRange(int precisionStep) { System.String field = "ascfield" + precisionStep; long lower = -1000L; long upper = +2000L; System.Double tempAux = (double)NumericUtils.SortableLongToDouble(lower); System.Double tempAux2 = (double)NumericUtils.SortableLongToDouble(upper); Query tq = NumericRangeQuery.NewDoubleRange(field, precisionStep, tempAux, tempAux2, true, true); TopDocs tTopDocs = searcher.Search(tq, 1); Assert.AreEqual(upper - lower + 1, tTopDocs.totalHits, "Returned count of range query must be equal to inclusive range length"); System.Double tempAux3 = (double)NumericUtils.SortableLongToDouble(lower); System.Double tempAux4 = (double)NumericUtils.SortableLongToDouble(upper); Filter tf = NumericRangeFilter.NewDoubleRange(field, precisionStep, tempAux3, tempAux4, true, true); tTopDocs = searcher.Search(new MatchAllDocsQuery(), tf, 1); Assert.AreEqual(upper - lower + 1, tTopDocs.totalHits, "Returned count of range filter must be equal to inclusive range length"); }