diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index e2dc0739795..26e2cb30663 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -240,8 +240,7 @@ Other Changes
* SOLR-14226: Fix or suppress 14 resource leak warnings in apache/solr/core (Andras Salaman via
Erick Erickson)
-* SOLR-14485: Fix or suppress 11 resource leak warnings in apache/solr/cloud (Andras Salaman via Erick Erickson)
-
+* SOLR-14482: Fix or suppress warnings in solr/search/facet (Erick Erickson)
================== 8.5.1 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/core/src/java/org/apache/solr/cloud/ExclusiveSliceProperty.java b/solr/core/src/java/org/apache/solr/cloud/ExclusiveSliceProperty.java
index bd9de94b6e1..448f4553c99 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ExclusiveSliceProperty.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ExclusiveSliceProperty.java
@@ -362,7 +362,7 @@ class ExclusiveSliceProperty {
this.replica = replica;
}
public String toString() {
- StringBuilder sb = new StringBuilder(System.lineSeparator()).append(System.lineSeparator()).append("******EOE20 starting toString of SliceReplica");
+ StringBuilder sb = new StringBuilder(System.lineSeparator()).append(System.lineSeparator());
sb.append(" :").append(System.lineSeparator()).append("slice: ").append(slice.toString()).append(System.lineSeparator()).append(" replica: ").append(replica.toString()).append(System.lineSeparator());
return sb.toString();
}
diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrMetricProducer.java b/solr/core/src/java/org/apache/solr/metrics/SolrMetricProducer.java
index c321a11012a..a7f24fdf757 100644
--- a/solr/core/src/java/org/apache/solr/metrics/SolrMetricProducer.java
+++ b/solr/core/src/java/org/apache/solr/metrics/SolrMetricProducer.java
@@ -16,6 +16,8 @@
*/
package org.apache.solr.metrics;
+import java.io.IOException;
+
/**
* Used by objects that expose metrics through {@link SolrMetricManager}.
*/
@@ -62,9 +64,14 @@ public interface SolrMetricProducer extends AutoCloseable {
* Implementations should always call SolrMetricProducer.super.close()
to ensure that
* metrics with the same life-cycle as this component are properly unregistered. This prevents
* obscure memory leaks.
+ *
+ * from: https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html
+ * While this interface method is declared to throw Exception, implementers are strongly encouraged
+ * to declare concrete implementations of the close method to throw more specific exceptions, or to
+ * throw no exception at all if the close operation cannot fail.
*/
@Override
- default void close() throws Exception {
+ default void close() throws IOException {
SolrMetricsContext context = getSolrMetricsContext();
if (context == null) {
return;
diff --git a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
index 596a05eef0f..e89d15edc92 100644
--- a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
@@ -78,7 +78,7 @@ public class JSONResponseWriter implements QueryResponseWriter {
return new JSONWriter(writer, req, rsp);
}
-}
+
/**
* Writes NamedLists directly as an array of NameTypeValue JSON objects...
@@ -248,9 +248,10 @@ class ArrayOfNameTypeValueJSONWriter extends JSONWriter {
}
}
-abstract class NaNFloatWriter extends JSONWriter {
-
+abstract static class NaNFloatWriter extends JSONWriter {
+
abstract protected String getNaN();
+
abstract protected String getInf();
public NaNFloatWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {
@@ -283,3 +284,4 @@ abstract class NaNFloatWriter extends JSONWriter {
}
}
}
+}
diff --git a/solr/core/src/java/org/apache/solr/response/PythonResponseWriter.java b/solr/core/src/java/org/apache/solr/response/PythonResponseWriter.java
index 98109df042f..be53ddb06c0 100644
--- a/solr/core/src/java/org/apache/solr/response/PythonResponseWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/PythonResponseWriter.java
@@ -46,7 +46,7 @@ public class PythonResponseWriter implements QueryResponseWriter {
}
}
-class PythonWriter extends NaNFloatWriter {
+class PythonWriter extends JSONResponseWriter.NaNFloatWriter {
@Override
protected String getNaN() { return "float('NaN')"; }
@Override
diff --git a/solr/core/src/java/org/apache/solr/response/RubyResponseWriter.java b/solr/core/src/java/org/apache/solr/response/RubyResponseWriter.java
index 6b73a7cfe1b..eb4c17d5a50 100644
--- a/solr/core/src/java/org/apache/solr/response/RubyResponseWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/RubyResponseWriter.java
@@ -46,7 +46,7 @@ public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) th
}
}
-class RubyWriter extends NaNFloatWriter {
+class RubyWriter extends JSONResponseWriter.NaNFloatWriter {
@Override
protected String getNaN() { return "(0.0/0.0)"; }
diff --git a/solr/core/src/java/org/apache/solr/search/CaffeineCache.java b/solr/core/src/java/org/apache/solr/search/CaffeineCache.java
index 82271ade225..318e0e889f1 100644
--- a/solr/core/src/java/org/apache/solr/search/CaffeineCache.java
+++ b/solr/core/src/java/org/apache/solr/search/CaffeineCache.java
@@ -16,6 +16,7 @@
*/
package org.apache.solr.search;
+import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.time.Duration;
import java.util.Collections;
@@ -228,7 +229,7 @@ public class CaffeineCache extends SolrCacheBase implements SolrCache extends SolrInfoBean {
/** Frees any non-memory resources */
- default void close() throws Exception {
+ default void close() throws IOException {
SolrInfoBean.super.close();
}
diff --git a/solr/core/src/java/org/apache/solr/search/facet/AggValueSource.java b/solr/core/src/java/org/apache/solr/search/facet/AggValueSource.java
index c633dbf43b3..da83b9125b7 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/AggValueSource.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/AggValueSource.java
@@ -44,13 +44,14 @@ public abstract class AggValueSource extends ValueSource {
}
@Override
+ @SuppressWarnings({"rawtypes"})
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
// FUTURE
throw new UnsupportedOperationException("NOT IMPLEMENTED " + name + " " + this);
}
// TODO: make abstract
- public SlotAcc createSlotAcc(FacetRequest.FacetContext fcontext, long numDocs, int numSlots) throws IOException {
+ public SlotAcc createSlotAcc(FacetContext fcontext, long numDocs, int numSlots) throws IOException {
throw new UnsupportedOperationException("NOT IMPLEMENTED " + name + " " + this);
}
diff --git a/solr/core/src/java/org/apache/solr/search/facet/AvgAgg.java b/solr/core/src/java/org/apache/solr/search/facet/AvgAgg.java
index e1a09a66c09..7036c302771 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/AvgAgg.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/AvgAgg.java
@@ -37,7 +37,7 @@ public class AvgAgg extends SimpleAggValueSource {
}
@Override
- public SlotAcc createSlotAcc(FacetRequest.FacetContext fcontext, long numDocs, int numSlots) throws IOException {
+ public SlotAcc createSlotAcc(FacetContext fcontext, long numDocs, int numSlots) throws IOException {
ValueSource vs = getArg();
if (vs instanceof FieldNameValueSource) {
@@ -62,7 +62,7 @@ public class AvgAgg extends SimpleAggValueSource {
}
vs = sf.getType().getValueSource(sf, null);
}
- return new AvgSlotAcc(vs, fcontext, numSlots);
+ return new SlotAcc.AvgSlotAcc(vs, fcontext, numSlots);
}
@Override
@@ -70,12 +70,13 @@ public class AvgAgg extends SimpleAggValueSource {
return new Merger();
}
- private static class Merger extends FacetDoubleMerger {
+ private static class Merger extends FacetModule.FacetDoubleMerger {
long num;
double sum;
@Override
public void merge(Object facetResult, Context mcontext1) {
+ @SuppressWarnings({"unchecked"})
List numberList = (List) facetResult;
num += numberList.get(0).longValue();
sum += numberList.get(1).doubleValue();
@@ -88,10 +89,10 @@ public class AvgAgg extends SimpleAggValueSource {
}
}
- class AvgSortedNumericAcc extends DoubleSortedNumericDVAcc {
+ class AvgSortedNumericAcc extends DocValuesAcc.DoubleSortedNumericDVAcc {
int[] counts;
- public AvgSortedNumericAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ public AvgSortedNumericAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
super(fcontext, sf, numSlots, 0);
this.counts = new int[numSlots];
}
@@ -114,6 +115,7 @@ public class AvgAgg extends SimpleAggValueSource {
}
@Override
+ @SuppressWarnings({"unchecked", "rawtypes"})
public Object getValue(int slot) {
if (fcontext.isShard()) {
ArrayList lst = new ArrayList(2);
@@ -138,10 +140,10 @@ public class AvgAgg extends SimpleAggValueSource {
}
}
- class AvgSortedSetAcc extends DoubleSortedSetDVAcc {
+ class AvgSortedSetAcc extends DocValuesAcc.DoubleSortedSetDVAcc {
int[] counts;
- public AvgSortedSetAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ public AvgSortedSetAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
super(fcontext, sf, numSlots, 0);
this.counts = new int[numSlots];
}
@@ -168,6 +170,7 @@ public class AvgAgg extends SimpleAggValueSource {
}
@Override
+ @SuppressWarnings({"unchecked", "rawtypes"})
public Object getValue(int slot) {
if (fcontext.isShard()) {
ArrayList lst = new ArrayList(2);
@@ -192,10 +195,10 @@ public class AvgAgg extends SimpleAggValueSource {
}
}
- class AvgUnInvertedFieldAcc extends DoubleUnInvertedFieldAcc {
+ class AvgUnInvertedFieldAcc extends UnInvertedFieldAcc.DoubleUnInvertedFieldAcc {
int[] counts;
- public AvgUnInvertedFieldAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ public AvgUnInvertedFieldAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
super(fcontext, sf, numSlots, 0);
this.counts = new int[numSlots];
}
@@ -224,6 +227,7 @@ public class AvgAgg extends SimpleAggValueSource {
}
@Override
+ @SuppressWarnings({"unchecked", "rawtypes"})
public Object getValue(int slot) {
if (fcontext.isShard()) {
ArrayList lst = new ArrayList(2);
diff --git a/solr/core/src/java/org/apache/solr/search/facet/CountAgg.java b/solr/core/src/java/org/apache/solr/search/facet/CountAgg.java
index 527399c681c..e2f4e9105a1 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/CountAgg.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/CountAgg.java
@@ -24,12 +24,12 @@ public class CountAgg extends SimpleAggValueSource {
}
@Override
- public SlotAcc createSlotAcc(FacetRequest.FacetContext fcontext, long numDocs, int numSlots) throws IOException {
- return new CountSlotArrAcc(fcontext, numSlots);
+ public SlotAcc createSlotAcc(FacetContext fcontext, long numDocs, int numSlots) throws IOException {
+ return new SlotAcc.CountSlotArrAcc(fcontext, numSlots);
}
@Override
public FacetMerger createFacetMerger(Object prototype) {
- return new FacetLongMerger();
+ return new FacetModule.FacetLongMerger();
}
}
diff --git a/solr/core/src/java/org/apache/solr/search/facet/CountValsAgg.java b/solr/core/src/java/org/apache/solr/search/facet/CountValsAgg.java
index 4923cc8b6dc..6415ff63529 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/CountValsAgg.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/CountValsAgg.java
@@ -37,7 +37,7 @@ public class CountValsAgg extends SimpleAggValueSource {
}
@Override
- public SlotAcc createSlotAcc(FacetRequest.FacetContext fcontext, long numDocs, int numSlots) throws IOException {
+ public SlotAcc createSlotAcc(FacetContext fcontext, long numDocs, int numSlots) throws IOException {
ValueSource vs = getArg();
if (vs instanceof FieldNameValueSource) {
String field = ((FieldNameValueSource)vs).getFieldName();
@@ -64,12 +64,12 @@ public class CountValsAgg extends SimpleAggValueSource {
@Override
public FacetMerger createFacetMerger(Object prototype) {
- return new FacetLongMerger();
+ return new FacetModule.FacetLongMerger();
}
- class CountValSlotAcc extends LongFuncSlotAcc {
+ class CountValSlotAcc extends SlotAcc.LongFuncSlotAcc {
- public CountValSlotAcc(ValueSource values, FacetRequest.FacetContext fcontext, int numSlots) {
+ public CountValSlotAcc(ValueSource values, FacetContext fcontext, int numSlots) {
super(values, fcontext, numSlots, 0);
}
@@ -81,9 +81,9 @@ public class CountValsAgg extends SimpleAggValueSource {
}
}
- class CountSortedNumericDVAcc extends LongSortedNumericDVAcc {
+ class CountSortedNumericDVAcc extends DocValuesAcc.LongSortedNumericDVAcc {
- public CountSortedNumericDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ public CountSortedNumericDVAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
super(fcontext, sf, numSlots, 0);
}
@@ -93,9 +93,9 @@ public class CountValsAgg extends SimpleAggValueSource {
}
}
- class CountSortedSetDVAcc extends LongSortedSetDVAcc {
+ class CountSortedSetDVAcc extends DocValuesAcc.LongSortedSetDVAcc {
- public CountSortedSetDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ public CountSortedSetDVAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
super(fcontext, sf, numSlots, 0);
}
@@ -111,7 +111,7 @@ public class CountValsAgg extends SimpleAggValueSource {
private int currentSlot;
long[] result;
- public CountMultiValuedAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ public CountMultiValuedAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
super(fcontext, sf, numSlots);
result = new long[numSlots];
}
diff --git a/solr/core/src/java/org/apache/solr/search/facet/DocValuesAcc.java b/solr/core/src/java/org/apache/solr/search/facet/DocValuesAcc.java
index 38c9f08bbbe..547040e0112 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/DocValuesAcc.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/DocValuesAcc.java
@@ -39,7 +39,7 @@ import org.apache.solr.schema.SchemaField;
public abstract class DocValuesAcc extends SlotAcc {
SchemaField sf;
- public DocValuesAcc(FacetRequest.FacetContext fcontext, SchemaField sf) throws IOException {
+ public DocValuesAcc(FacetContext fcontext, SchemaField sf) throws IOException {
super(fcontext);
this.sf = sf;
}
@@ -58,368 +58,371 @@ public abstract class DocValuesAcc extends SlotAcc {
* returns whether or not given {@code doc} has value
*/
protected abstract boolean advanceExact(int doc) throws IOException;
-}
-/**
- * Accumulator for {@link NumericDocValues}
- */
-abstract class NumericDVAcc extends DocValuesAcc {
- NumericDocValues values;
- public NumericDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf) throws IOException {
- super(fcontext, sf);
- }
+ /**
+ * Accumulator for {@link NumericDocValues}
+ */
+ abstract class NumericDVAcc extends DocValuesAcc {
+ NumericDocValues values;
- @Override
- public void setNextReader(LeafReaderContext readerContext) throws IOException {
- super.setNextReader(readerContext);
- values = DocValues.getNumeric(readerContext.reader(), sf.getName());
- }
-
- @Override
- protected boolean advanceExact(int doc) throws IOException {
- return values.advanceExact(doc);
- }
-}
-
-/**
- * Accumulator for {@link SortedNumericDocValues}
- */
-abstract class SortedNumericDVAcc extends DocValuesAcc {
- SortedNumericDocValues values;
-
- public SortedNumericDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
- super(fcontext, sf);
- }
-
- @Override
- public void setNextReader(LeafReaderContext readerContext) throws IOException {
- super.setNextReader(readerContext);
- values = DocValues.getSortedNumeric(readerContext.reader(), sf.getName());
- }
-
- @Override
- protected boolean advanceExact(int doc) throws IOException {
- return values.advanceExact(doc);
- }
-}
-
-abstract class LongSortedNumericDVAcc extends SortedNumericDVAcc {
- long[] result;
- long initialValue;
-
- public LongSortedNumericDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots, long initialValue) throws IOException {
- super(fcontext, sf, numSlots);
- this.result = new long[numSlots];
- this.initialValue = initialValue;
- if (initialValue != 0) {
- Arrays.fill(result, initialValue);
+ public NumericDVAcc(FacetContext fcontext, SchemaField sf) throws IOException {
+ super(fcontext, sf);
}
- }
- @Override
- public int compare(int slotA, int slotB) {
- return Long.compare(result[slotA], result[slotB]);
- }
-
- @Override
- public Object getValue(int slotNum) throws IOException {
- return result[slotNum];
- }
-
- @Override
- public void reset() throws IOException {
- Arrays.fill(result, initialValue);
- }
-
- @Override
- public void resize(Resizer resizer) {
- this.result = resizer.resize(result, initialValue);
- }
-
-}
-
-abstract class DoubleSortedNumericDVAcc extends SortedNumericDVAcc {
- double[] result;
- double initialValue;
-
- public DoubleSortedNumericDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots, double initialValue) throws IOException {
- super(fcontext, sf, numSlots);
- this.result = new double[numSlots];
- this.initialValue = initialValue;
- if (initialValue != 0) {
- Arrays.fill(result, initialValue);
+ @Override
+ public void setNextReader(LeafReaderContext readerContext) throws IOException {
+ super.setNextReader(readerContext);
+ values = DocValues.getNumeric(readerContext.reader(), sf.getName());
}
- }
- @Override
- public int compare(int slotA, int slotB) {
- return Double.compare(result[slotA], result[slotB]);
- }
-
- @Override
- public Object getValue(int slotNum) throws IOException {
- return result[slotNum];
- }
-
- @Override
- public void reset() throws IOException {
- Arrays.fill(result, initialValue);
- }
-
- @Override
- public void resize(Resizer resizer) {
- this.result = resizer.resize(result, initialValue);
+ @Override
+ protected boolean advanceExact(int doc) throws IOException {
+ return values.advanceExact(doc);
+ }
}
/**
- * converts given long value to double based on field type
+ * Accumulator for {@link SortedNumericDocValues}
*/
- protected double getDouble(long val) {
- switch (sf.getType().getNumberType()) {
- case INTEGER:
- case LONG:
- case DATE:
- return val;
- case FLOAT:
- return NumericUtils.sortableIntToFloat((int) val);
- case DOUBLE:
- return NumericUtils.sortableLongToDouble(val);
- default:
- // this would never happen
- return 0.0d;
+ abstract static class SortedNumericDVAcc extends DocValuesAcc {
+ SortedNumericDocValues values;
+
+ public SortedNumericDVAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ super(fcontext, sf);
+ }
+
+ @Override
+ public void setNextReader(LeafReaderContext readerContext) throws IOException {
+ super.setNextReader(readerContext);
+ values = DocValues.getSortedNumeric(readerContext.reader(), sf.getName());
+ }
+
+ @Override
+ protected boolean advanceExact(int doc) throws IOException {
+ return values.advanceExact(doc);
}
}
-}
+ abstract static class LongSortedNumericDVAcc extends SortedNumericDVAcc {
+ long[] result;
+ long initialValue;
-/**
- * Base class for standard deviation and variance computation for fields with {@link SortedNumericDocValues}
- */
-abstract class SDVSortedNumericAcc extends DoubleSortedNumericDVAcc {
- int[] counts;
- double[] sum;
-
- public SDVSortedNumericAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
- super(fcontext, sf, numSlots, 0);
- this.counts = new int[numSlots];
- this.sum = new double[numSlots];
- }
-
- @Override
- protected void collectValues(int doc, int slot) throws IOException {
- for (int i = 0, count = values.docValueCount(); i < count; i++) {
- double val = getDouble(values.nextValue());
- result[slot]+= val * val;
- sum[slot]+= val;
- counts[slot]++;
+ public LongSortedNumericDVAcc(FacetContext fcontext, SchemaField sf, int numSlots, long initialValue) throws IOException {
+ super(fcontext, sf, numSlots);
+ this.result = new long[numSlots];
+ this.initialValue = initialValue;
+ if (initialValue != 0) {
+ Arrays.fill(result, initialValue);
+ }
}
- }
- protected abstract double computeVal(int slot);
-
- @Override
- public int compare(int slotA, int slotB) {
- return Double.compare(computeVal(slotA), computeVal(slotB));
- }
-
- @Override
- public Object getValue(int slot) {
- if (fcontext.isShard()) {
- ArrayList lst = new ArrayList(3);
- lst.add(counts[slot]);
- lst.add(result[slot]);
- lst.add(sum[slot]);
- return lst;
- } else {
- return computeVal(slot);
+ @Override
+ public int compare(int slotA, int slotB) {
+ return Long.compare(result[slotA], result[slotB]);
}
- }
- @Override
- public void reset() throws IOException {
- super.reset();
- Arrays.fill(counts, 0);
- Arrays.fill(sum, 0);
- }
+ @Override
+ public Object getValue(int slotNum) throws IOException {
+ return result[slotNum];
+ }
- @Override
- public void resize(Resizer resizer) {
- super.resize(resizer);
- this.counts = resizer.resize(counts, 0);
- this.sum = resizer.resize(sum, 0);
- }
-}
-
-/**
- * Accumulator for {@link SortedDocValues}
- */
-abstract class SortedDVAcc extends DocValuesAcc {
- SortedDocValues values;
-
- public SortedDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf) throws IOException {
- super(fcontext, sf);
- }
-
- @Override
- public void setNextReader(LeafReaderContext readerContext) throws IOException {
- super.setNextReader(readerContext);
- values = DocValues.getSorted(readerContext.reader(), sf.getName());
- }
-
- @Override
- protected boolean advanceExact(int doc) throws IOException {
- return values.advanceExact(doc);
- }
-}
-
-/**
- * Accumulator for {@link SortedSetDocValues}
- */
-abstract class SortedSetDVAcc extends DocValuesAcc {
- SortedSetDocValues values;
-
- public SortedSetDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
- super(fcontext, sf);
- }
-
- @Override
- public void setNextReader(LeafReaderContext readerContext) throws IOException {
- super.setNextReader(readerContext);
- values = DocValues.getSortedSet(readerContext.reader(), sf.getName());
- }
-
- @Override
- protected boolean advanceExact(int doc) throws IOException {
- return values.advanceExact(doc);
- }
-}
-
-abstract class LongSortedSetDVAcc extends SortedSetDVAcc {
- long[] result;
- long initialValue;
-
- public LongSortedSetDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots, long initialValue) throws IOException {
- super(fcontext, sf, numSlots);
- result = new long[numSlots];
- this.initialValue = initialValue;
- if (initialValue != 0) {
+ @Override
+ public void reset() throws IOException {
Arrays.fill(result, initialValue);
}
- }
- @Override
- public int compare(int slotA, int slotB) {
- return Long.compare(result[slotA], result[slotB]);
- }
-
- @Override
- public Object getValue(int slotNum) throws IOException {
- return result[slotNum];
- }
-
- @Override
- public void reset() throws IOException {
- Arrays.fill(result, initialValue);
- }
-
- @Override
- public void resize(Resizer resizer) {
+ @Override
+ public void resize(Resizer resizer) {
this.result = resizer.resize(result, initialValue);
+ }
+
}
-}
-abstract class DoubleSortedSetDVAcc extends SortedSetDVAcc {
- double[] result;
- double initialValue;
+ abstract static class DoubleSortedNumericDVAcc extends SortedNumericDVAcc {
+ double[] result;
+ double initialValue;
- public DoubleSortedSetDVAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots, long initialValue) throws IOException {
- super(fcontext, sf, numSlots);
- result = new double[numSlots];
- this.initialValue = initialValue;
- if (initialValue != 0) {
+ public DoubleSortedNumericDVAcc(FacetContext fcontext, SchemaField sf, int numSlots, double initialValue) throws IOException {
+ super(fcontext, sf, numSlots);
+ this.result = new double[numSlots];
+ this.initialValue = initialValue;
+ if (initialValue != 0) {
+ Arrays.fill(result, initialValue);
+ }
+ }
+
+ @Override
+ public int compare(int slotA, int slotB) {
+ return Double.compare(result[slotA], result[slotB]);
+ }
+
+ @Override
+ public Object getValue(int slotNum) throws IOException {
+ return result[slotNum];
+ }
+
+ @Override
+ public void reset() throws IOException {
Arrays.fill(result, initialValue);
}
- }
- @Override
- public int compare(int slotA, int slotB) {
- return Double.compare(result[slotA], result[slotB]);
- }
-
- @Override
- public Object getValue(int slotNum) throws IOException {
- return result[slotNum];
- }
-
- @Override
- public void reset() throws IOException {
- Arrays.fill(result, initialValue);
- }
-
- @Override
- public void resize(Resizer resizer) {
+ @Override
+ public void resize(Resizer resizer) {
this.result = resizer.resize(result, initialValue);
- }
-}
-
-/**
- * Base class for standard deviation and variance computation for fields with {@link SortedSetDocValues}
- */
-abstract class SDVSortedSetAcc extends DoubleSortedSetDVAcc {
- int[] counts;
- double[] sum;
-
- public SDVSortedSetAcc(FacetRequest.FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
- super(fcontext, sf, numSlots, 0);
- this.counts = new int[numSlots];
- this.sum = new double[numSlots];
- }
-
- @Override
- protected void collectValues(int doc, int slot) throws IOException {
- long ord;
- while ((ord = values.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
- BytesRef term = values.lookupOrd(ord);
- Object obj = sf.getType().toObject(sf, term);
- double val = obj instanceof Date ? ((Date)obj).getTime(): ((Number)obj).doubleValue();
- result[slot] += val * val;
- sum[slot] += val;
- counts[slot]++;
}
- }
- protected abstract double computeVal(int slot);
-
- @Override
- public int compare(int slotA, int slotB) {
- return Double.compare(computeVal(slotA), computeVal(slotB));
- }
-
- @Override
- public Object getValue(int slot) {
- if (fcontext.isShard()) {
- ArrayList lst = new ArrayList(3);
- lst.add(counts[slot]);
- lst.add(result[slot]);
- lst.add(sum[slot]);
- return lst;
- } else {
- return computeVal(slot);
+ /**
+ * converts given long value to double based on field type
+ */
+ protected double getDouble(long val) {
+ switch (sf.getType().getNumberType()) {
+ case INTEGER:
+ case LONG:
+ case DATE:
+ return val;
+ case FLOAT:
+ return NumericUtils.sortableIntToFloat((int) val);
+ case DOUBLE:
+ return NumericUtils.sortableLongToDouble(val);
+ default:
+ // this would never happen
+ return 0.0d;
+ }
}
+
}
- @Override
- public void reset() throws IOException {
- super.reset();
- Arrays.fill(counts, 0);
- Arrays.fill(sum, 0);
- }
+ /**
+ * Base class for standard deviation and variance computation for fields with {@link SortedNumericDocValues}
+ */
+ abstract static class SDVSortedNumericAcc extends DoubleSortedNumericDVAcc {
+ int[] counts;
+ double[] sum;
- @Override
- public void resize(Resizer resizer) {
- super.resize(resizer);
+ public SDVSortedNumericAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ super(fcontext, sf, numSlots, 0);
+ this.counts = new int[numSlots];
+ this.sum = new double[numSlots];
+ }
+
+ @Override
+ protected void collectValues(int doc, int slot) throws IOException {
+ for (int i = 0, count = values.docValueCount(); i < count; i++) {
+ double val = getDouble(values.nextValue());
+ result[slot] += val * val;
+ sum[slot] += val;
+ counts[slot]++;
+ }
+ }
+
+ protected abstract double computeVal(int slot);
+
+ @Override
+ public int compare(int slotA, int slotB) {
+ return Double.compare(computeVal(slotA), computeVal(slotB));
+ }
+
+ @Override
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public Object getValue(int slot) {
+ if (fcontext.isShard()) {
+ ArrayList lst = new ArrayList(3);
+ lst.add(counts[slot]);
+ lst.add(result[slot]);
+ lst.add(sum[slot]);
+ return lst;
+ } else {
+ return computeVal(slot);
+ }
+ }
+
+ @Override
+ public void reset() throws IOException {
+ super.reset();
+ Arrays.fill(counts, 0);
+ Arrays.fill(sum, 0);
+ }
+
+ @Override
+ public void resize(Resizer resizer) {
+ super.resize(resizer);
this.counts = resizer.resize(counts, 0);
this.sum = resizer.resize(sum, 0);
+ }
+ }
+
+ /**
+ * Accumulator for {@link SortedDocValues}
+ */
+ abstract class SortedDVAcc extends DocValuesAcc {
+ SortedDocValues values;
+
+ public SortedDVAcc(FacetContext fcontext, SchemaField sf) throws IOException {
+ super(fcontext, sf);
+ }
+
+ @Override
+ public void setNextReader(LeafReaderContext readerContext) throws IOException {
+ super.setNextReader(readerContext);
+ values = DocValues.getSorted(readerContext.reader(), sf.getName());
+ }
+
+ @Override
+ protected boolean advanceExact(int doc) throws IOException {
+ return values.advanceExact(doc);
+ }
+ }
+
+ /**
+ * Accumulator for {@link SortedSetDocValues}
+ */
+ abstract static class SortedSetDVAcc extends DocValuesAcc {
+ SortedSetDocValues values;
+
+ public SortedSetDVAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ super(fcontext, sf);
+ }
+
+ @Override
+ public void setNextReader(LeafReaderContext readerContext) throws IOException {
+ super.setNextReader(readerContext);
+ values = DocValues.getSortedSet(readerContext.reader(), sf.getName());
+ }
+
+ @Override
+ protected boolean advanceExact(int doc) throws IOException {
+ return values.advanceExact(doc);
+ }
+ }
+
+ abstract static class LongSortedSetDVAcc extends SortedSetDVAcc {
+ long[] result;
+ long initialValue;
+
+ public LongSortedSetDVAcc(FacetContext fcontext, SchemaField sf, int numSlots, long initialValue) throws IOException {
+ super(fcontext, sf, numSlots);
+ result = new long[numSlots];
+ this.initialValue = initialValue;
+ if (initialValue != 0) {
+ Arrays.fill(result, initialValue);
+ }
+ }
+
+ @Override
+ public int compare(int slotA, int slotB) {
+ return Long.compare(result[slotA], result[slotB]);
+ }
+
+ @Override
+ public Object getValue(int slotNum) throws IOException {
+ return result[slotNum];
+ }
+
+ @Override
+ public void reset() throws IOException {
+ Arrays.fill(result, initialValue);
+ }
+
+ @Override
+ public void resize(Resizer resizer) {
+ this.result = resizer.resize(result, initialValue);
+ }
+ }
+
+ abstract static class DoubleSortedSetDVAcc extends SortedSetDVAcc {
+ double[] result;
+ double initialValue;
+
+ public DoubleSortedSetDVAcc(FacetContext fcontext, SchemaField sf, int numSlots, long initialValue) throws IOException {
+ super(fcontext, sf, numSlots);
+ result = new double[numSlots];
+ this.initialValue = initialValue;
+ if (initialValue != 0) {
+ Arrays.fill(result, initialValue);
+ }
+ }
+
+ @Override
+ public int compare(int slotA, int slotB) {
+ return Double.compare(result[slotA], result[slotB]);
+ }
+
+ @Override
+ public Object getValue(int slotNum) throws IOException {
+ return result[slotNum];
+ }
+
+ @Override
+ public void reset() throws IOException {
+ Arrays.fill(result, initialValue);
+ }
+
+ @Override
+ public void resize(Resizer resizer) {
+ this.result = resizer.resize(result, initialValue);
+ }
+ }
+
+ /**
+ * Base class for standard deviation and variance computation for fields with {@link SortedSetDocValues}
+ */
+ abstract static class SDVSortedSetAcc extends DoubleSortedSetDVAcc {
+ int[] counts;
+ double[] sum;
+
+ public SDVSortedSetAcc(FacetContext fcontext, SchemaField sf, int numSlots) throws IOException {
+ super(fcontext, sf, numSlots, 0);
+ this.counts = new int[numSlots];
+ this.sum = new double[numSlots];
+ }
+
+ @Override
+ protected void collectValues(int doc, int slot) throws IOException {
+ long ord;
+ while ((ord = values.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
+ BytesRef term = values.lookupOrd(ord);
+ Object obj = sf.getType().toObject(sf, term);
+ double val = obj instanceof Date ? ((Date) obj).getTime() : ((Number) obj).doubleValue();
+ result[slot] += val * val;
+ sum[slot] += val;
+ counts[slot]++;
+ }
+ }
+
+ protected abstract double computeVal(int slot);
+
+ @Override
+ public int compare(int slotA, int slotB) {
+ return Double.compare(computeVal(slotA), computeVal(slotB));
+ }
+
+ @Override
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public Object getValue(int slot) {
+ if (fcontext.isShard()) {
+ ArrayList lst = new ArrayList(3);
+ lst.add(counts[slot]);
+ lst.add(result[slot]);
+ lst.add(sum[slot]);
+ return lst;
+ } else {
+ return computeVal(slot);
+ }
+ }
+
+ @Override
+ public void reset() throws IOException {
+ super.reset();
+ Arrays.fill(counts, 0);
+ Arrays.fill(sum, 0);
+ }
+
+ @Override
+ public void resize(Resizer resizer) {
+ super.resize(resizer);
+ this.counts = resizer.resize(counts, 0);
+ this.sum = resizer.resize(sum, 0);
+ }
}
}
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetBucket.java b/solr/core/src/java/org/apache/solr/search/facet/FacetBucket.java
index ae1eba68488..eadf60de465 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetBucket.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetBucket.java
@@ -24,14 +24,17 @@ import java.util.Map;
import org.apache.solr.common.util.SimpleOrderedMap;
public class FacetBucket {
- final FacetBucketMerger parent;
+ @SuppressWarnings("rawtypes")
+ final FacetModule.FacetBucketMerger parent;
+ @SuppressWarnings({"rawtypes"})
final Comparable bucketValue;
final int bucketNumber; // this is just for internal correlation (the first bucket created is bucket 0, the next bucket 1, across all field buckets)
long count;
Map subs;
- public FacetBucket(FacetBucketMerger parent, Comparable bucketValue, FacetMerger.Context mcontext) {
+ public FacetBucket(@SuppressWarnings("rawtypes") FacetModule.FacetBucketMerger parent
+ , @SuppressWarnings("rawtypes") Comparable bucketValue, FacetMerger.Context mcontext) {
this.parent = parent;
this.bucketValue = bucketValue;
this.bucketNumber = mcontext.getNewBucketNumber(); // TODO: we don't need bucket numbers for all buckets...
@@ -66,7 +69,7 @@ public class FacetBucket {
return merger;
}
- public void mergeBucket(SimpleOrderedMap bucket, FacetMerger.Context mcontext) {
+ public void mergeBucket(@SuppressWarnings("rawtypes") SimpleOrderedMap bucket, FacetMerger.Context mcontext) {
// todo: for refinements, we want to recurse, but not re-do stats for intermediate buckets
mcontext.setShardFlag(bucketNumber);
@@ -93,6 +96,7 @@ public class FacetBucket {
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
public SimpleOrderedMap getMergedBucket() {
SimpleOrderedMap out = new SimpleOrderedMap( (subs == null ? 0 : subs.size()) + 2 );
if (bucketValue != null) {
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetContext.java b/solr/core/src/java/org/apache/solr/search/facet/FacetContext.java
new file mode 100644
index 00000000000..86aa3add7fc
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetContext.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search.facet;
+
+import java.util.Map;
+
+import org.apache.lucene.search.Query;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.search.DocSet;
+import org.apache.solr.search.QueryContext;
+import org.apache.solr.search.SolrIndexSearcher;
+
+public class FacetContext {
+ // Context info for actually executing a local facet command
+ public static final int IS_SHARD=0x01;
+ public static final int IS_REFINEMENT=0x02;
+ public static final int SKIP_FACET=0x04; // refinement: skip calculating this immediate facet, but proceed to specific sub-facets based on facetInfo
+
+ FacetProcessor> processor;
+ Map facetInfo; // refinement info for this node
+ QueryContext qcontext;
+ SolrQueryRequest req; // TODO: replace with params?
+ SolrIndexSearcher searcher;
+ Query filter; // TODO: keep track of as a DocSet or as a Query?
+ DocSet base;
+ FacetContext parent;
+ int flags;
+ FacetDebugInfo debugInfo;
+
+ public void setDebugInfo(FacetDebugInfo debugInfo) {
+ this.debugInfo = debugInfo;
+ }
+
+ public FacetDebugInfo getDebugInfo() {
+ return debugInfo;
+ }
+
+ public boolean isShard() {
+ return (flags & IS_SHARD) != 0;
+ }
+
+ /**
+ * @param filter The filter for the bucket that resulted in this context/domain. Can be null if this is the root context.
+ * @param domain The resulting set of documents for this facet.
+ */
+ public FacetContext sub(Query filter, DocSet domain) {
+ FacetContext ctx = new FacetContext();
+ ctx.parent = this;
+ ctx.base = domain;
+ ctx.filter = filter;
+
+ // carry over from parent
+ ctx.flags = flags;
+ ctx.qcontext = qcontext;
+ ctx.req = req;
+ ctx.searcher = searcher;
+
+ return ctx;
+ }
+}
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetDebugInfo.java b/solr/core/src/java/org/apache/solr/search/facet/FacetDebugInfo.java
index 2be2fef2d5d..d6a36509d29 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetDebugInfo.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetDebugInfo.java
@@ -65,7 +65,7 @@ public class FacetDebugInfo {
return info;
}
- public SimpleOrderedMap getFacetDebugInfo() {
+ public SimpleOrderedMap