mirror of https://github.com/apache/lucene.git
SOLR-12271: Fix for analytics component reading negative values from double and float fields.
This commit is contained in:
parent
0e4512c231
commit
0ef8e5aa80
|
@ -23,7 +23,6 @@ import java.util.function.DoubleConsumer;
|
||||||
import org.apache.lucene.index.DocValues;
|
import org.apache.lucene.index.DocValues;
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.NumericDocValues;
|
import org.apache.lucene.index.NumericDocValues;
|
||||||
import org.apache.lucene.util.NumericUtils;
|
|
||||||
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
|
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
|
||||||
import org.apache.solr.analytics.value.DoubleValue.CastingDoubleValue;
|
import org.apache.solr.analytics.value.DoubleValue.CastingDoubleValue;
|
||||||
import org.apache.solr.schema.DoublePointField;
|
import org.apache.solr.schema.DoublePointField;
|
||||||
|
@ -50,7 +49,7 @@ public class DoubleField extends AnalyticsField implements CastingDoubleValue {
|
||||||
public void collect(int doc) throws IOException {
|
public void collect(int doc) throws IOException {
|
||||||
exists = docValues.advanceExact(doc);
|
exists = docValues.advanceExact(doc);
|
||||||
if (exists) {
|
if (exists) {
|
||||||
value = NumericUtils.sortableLongToDouble(docValues.longValue());
|
value = Double.longBitsToDouble(docValues.longValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.util.function.DoubleConsumer;
|
||||||
import org.apache.lucene.index.DocValues;
|
import org.apache.lucene.index.DocValues;
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.NumericDocValues;
|
import org.apache.lucene.index.NumericDocValues;
|
||||||
import org.apache.lucene.util.NumericUtils;
|
|
||||||
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
|
import org.apache.solr.analytics.facet.compare.ExpressionComparator;
|
||||||
import org.apache.solr.analytics.util.function.FloatConsumer;
|
import org.apache.solr.analytics.util.function.FloatConsumer;
|
||||||
import org.apache.solr.analytics.value.FloatValue.CastingFloatValue;
|
import org.apache.solr.analytics.value.FloatValue.CastingFloatValue;
|
||||||
|
@ -51,7 +50,7 @@ public class FloatField extends AnalyticsField implements CastingFloatValue {
|
||||||
public void collect(int doc) throws IOException {
|
public void collect(int doc) throws IOException {
|
||||||
exists = docValues.advanceExact(doc);
|
exists = docValues.advanceExact(doc);
|
||||||
if (exists) {
|
if (exists) {
|
||||||
value = NumericUtils.sortableIntToFloat((int)docValues.longValue());
|
value = Float.intBitsToFloat((int)docValues.longValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,11 +84,11 @@ public class AbstractAnalyticsFieldTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
missingDocuments = new ArrayList<>();
|
missingDocuments = new ArrayList<>();
|
||||||
|
|
||||||
assertU(adoc("id", "-1"));
|
assertU(adoc("id", "-2"));
|
||||||
missingDocuments.add("-1");
|
missingDocuments.add("-2");
|
||||||
assertU(adoc("id", "5"));
|
assertU(adoc("id", "5"));
|
||||||
missingDocuments.add("5");
|
missingDocuments.add("5");
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = -1; i < 5; ++i) {
|
||||||
assertU(adoc(
|
assertU(adoc(
|
||||||
"id", "" + i,
|
"id", "" + i,
|
||||||
|
|
||||||
|
@ -140,17 +140,17 @@ public class AbstractAnalyticsFieldTest extends SolrTestCaseJ4 {
|
||||||
"double_dm_p", "" + (i + 10.5),
|
"double_dm_p", "" + (i + 10.5),
|
||||||
"double_dm_p", "" + (i + 20.5),
|
"double_dm_p", "" + (i + 20.5),
|
||||||
|
|
||||||
"date_dt_t", "180" + i + "-12-31T23:59:59Z",
|
"date_dt_t", (1800 + i) + "-12-31T23:59:59Z",
|
||||||
"date_dtm_t", "180" + i + "-12-31T23:59:59Z",
|
"date_dtm_t", (1800 + i) + "-12-31T23:59:59Z",
|
||||||
"date_dtm_t", "18" + (i + 10) + "-12-31T23:59:59Z",
|
"date_dtm_t", (1800 + i + 10) + "-12-31T23:59:59Z",
|
||||||
"date_dtm_t", "18" + (i + 10) + "-12-31T23:59:59Z",
|
"date_dtm_t", (1800 + i + 10) + "-12-31T23:59:59Z",
|
||||||
"date_dtm_t", "18" + (i + 20) + "-12-31T23:59:59Z",
|
"date_dtm_t", (1800 + i + 20) + "-12-31T23:59:59Z",
|
||||||
|
|
||||||
"date_dt_p", "180" + i + "-12-31T23:59:59Z",
|
"date_dt_p", (1800 + i) + "-12-31T23:59:59Z",
|
||||||
"date_dtm_p", "180" + i + "-12-31T23:59:59Z",
|
"date_dtm_p", (1800 + i) + "-12-31T23:59:59Z",
|
||||||
"date_dtm_p", "18" + (i + 10) + "-12-31T23:59:59Z",
|
"date_dtm_p", (1800 + i + 10) + "-12-31T23:59:59Z",
|
||||||
"date_dtm_p", "18" + (i + 10) + "-12-31T23:59:59Z",
|
"date_dtm_p", (1800 + i + 10) + "-12-31T23:59:59Z",
|
||||||
"date_dtm_p", "18" + (i + 20) + "-12-31T23:59:59Z",
|
"date_dtm_p", (1800 + i + 20) + "-12-31T23:59:59Z",
|
||||||
|
|
||||||
"string_s", "abc" + i,
|
"string_s", "abc" + i,
|
||||||
"string_sm", "abc" + i,
|
"string_sm", "abc" + i,
|
||||||
|
@ -192,11 +192,11 @@ public class AbstractAnalyticsFieldTest extends SolrTestCaseJ4 {
|
||||||
doubles.put(i + 20.5, 1);
|
doubles.put(i + 20.5, 1);
|
||||||
multiDoubles.put(""+i, doubles);
|
multiDoubles.put(""+i, doubles);
|
||||||
|
|
||||||
singleDates.put(""+i, Instant.parse("180" + i + "-12-31T23:59:59Z").toEpochMilli());
|
singleDates.put(""+i, Instant.parse((1800 + i) + "-12-31T23:59:59Z").toEpochMilli());
|
||||||
Map<Long, Integer> dates = new HashMap<>();
|
Map<Long, Integer> dates = new HashMap<>();
|
||||||
dates.put(Instant.parse("180" + i + "-12-31T23:59:59Z").toEpochMilli(), 1);
|
dates.put(Instant.parse((1800 + i) + "-12-31T23:59:59Z").toEpochMilli(), 1);
|
||||||
dates.put(Instant.parse("18" + ( i + 10 ) + "-12-31T23:59:59Z").toEpochMilli(), 2);
|
dates.put(Instant.parse((1800 + i + 10) + "-12-31T23:59:59Z").toEpochMilli(), 2);
|
||||||
dates.put(Instant.parse("18" + ( i + 20 ) + "-12-31T23:59:59Z").toEpochMilli(), 1);
|
dates.put(Instant.parse((1800 + i + 20) + "-12-31T23:59:59Z").toEpochMilli(), 1);
|
||||||
multiDates.put(""+i, dates);
|
multiDates.put(""+i, dates);
|
||||||
|
|
||||||
singleStrings.put(""+i, "abc" + i);
|
singleStrings.put(""+i, "abc" + i);
|
||||||
|
|
Loading…
Reference in New Issue