Skip to content

Apache Lucene open-source search software

LUCENE-5339: remove RangeAccumulator/FacetRequest

Michael McCandlessfcd40a6f93b7
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/RangeAccumulator.java b/lucene/facet/src/java/org/apache/lucene/facet/range/RangeAccumulator.java
deleted file mode 100644
index 7a7c54b7078..00000000000
--- a/lucene/facet/src/java/org/apache/lucene/facet/range/RangeAccumulator.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package org.apache.lucene.facet.range;
-
-/*
- * 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.
- */
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.lucene.facet.params.FacetSearchParams;
-import org.apache.lucene.facet.search.FacetRequest;
-import org.apache.lucene.facet.search.FacetResult;
-import org.apache.lucene.facet.search.FacetResultNode;
-import org.apache.lucene.facet.search.FacetsAccumulator;
-import org.apache.lucene.facet.search.FacetsCollector.MatchingDocs;
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.queries.function.FunctionValues;
-
-/**
- * Uses {@link RangeFacetRequest#getValues(AtomicReaderContext)} and accumulates
- * counts for provided ranges.
- */
-public class RangeAccumulator extends FacetsAccumulator {
-
- public RangeAccumulator(FacetRequest... facetRequests) {
- this(Arrays.asList(facetRequests));
- }
-
- public RangeAccumulator(List<FacetRequest> facetRequests) {
- super(new FacetSearchParams(facetRequests));
- for (FacetRequest fr : facetRequests) {
- if (!(fr instanceof RangeFacetRequest)) {
- throw new IllegalArgumentException("this accumulator only supports RangeFacetRequest; got " + fr);
- }
-
- if (fr.categoryPath.length != 1) {
- throw new IllegalArgumentException("only flat (dimension only) CategoryPath is allowed");
- }
- }
- }
-
- @Override
- public List<FacetResult> accumulate(List<MatchingDocs> matchingDocs) throws IOException {
-
- // TODO: test if this is faster (in the past it was
- // faster to do MachingDocs on the inside) ... see
- // patches on LUCENE-4965):
- List<FacetResult> results = new ArrayList<FacetResult>();
- for (FacetRequest req : searchParams.facetRequests) {
- RangeFacetRequest<?> rangeFR = (RangeFacetRequest<?>) req;
- int[] counts = new int[rangeFR.ranges.length];
- for (MatchingDocs hits : matchingDocs) {
- FunctionValues fv = rangeFR.getValues(hits.context);
- final int length = hits.bits.length();
- int doc = 0;
- while (doc < length && (doc = hits.bits.nextSetBit(doc)) != -1) {
- // Skip missing docs:
- if (!fv.exists(doc)) {
- ++doc;
- continue;
- }
-
- long v = fv.longVal(doc);
-
- // TODO: if all ranges are non-overlapping, we
- // should instead do a bin-search up front
- // (really, a specialized case of the interval
- // tree)
- // TODO: use interval tree instead of linear search:
- for (int j = 0; j < rangeFR.ranges.length; j++) {
- if (rangeFR.ranges[j].accept(v)) {
- counts[j]++;
- }
- }
-
- doc++;
- }
- }
-
- List<FacetResultNode> nodes = new ArrayList<FacetResultNode>(rangeFR.ranges.length);
- for (int j = 0; j < rangeFR.ranges.length; j++) {
- nodes.add(new RangeFacetResultNode(rangeFR.label, rangeFR.ranges[j], counts[j]));
- }
-
- FacetResultNode rootNode = new FacetResultNode(-1, 0);
- rootNode.label = rangeFR.categoryPath;
- rootNode.subResults = nodes;
-
- results.add(new FacetResult(req, rootNode, nodes.size()));
- }
-
- return results;
- }
-
- @Override
- public boolean requiresDocScores() {
- return false;
- }
-}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetRequest.java b/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetRequest.java
deleted file mode 100644
index 86fe74a6e2b..00000000000
--- a/lucene/facet/src/java/org/apache/lucene/facet/range/RangeFacetRequest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package org.apache.lucene.facet.range;
-
-/*
- * 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.
- */
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.lucene.facet.params.FacetIndexingParams;
-import org.apache.lucene.facet.search.FacetRequest;
-import org.apache.lucene.facet.search.FacetResultNode;
-import org.apache.lucene.facet.search.FacetsAggregator;
-import org.apache.lucene.facet.taxonomy.FacetLabel;
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.lucene.queries.function.FunctionValues;
-import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.queries.function.valuesource.LongFieldSource;
-
-/**
- * A {@link FacetRequest} for dynamic ranges based on a {@link NumericDocValues}
- * field or {@link ValueSource}. This does not use the taxonomy index nor any
- * indexed facet values.
- *
- * @lucene.experimental
- */
-public class RangeFacetRequest<T extends Range> extends FacetRequest {
-
- public final Range[] ranges;
- public final String label;
-
- private final ValueSource valueSource;
-
- /**
- * Create a request for the given ranges over the specified
- * {@link NumericDocValues} field. The field will be used to as the root's
- * {@link FacetResultNode} label.
- */
- @SuppressWarnings("unchecked")
- public RangeFacetRequest(String field, T...ranges) {
- this(field, new LongFieldSource(field), ranges);
- }
-
- /**
- * Create a request for the given ranges over the specified
- * {@link NumericDocValues} field. The field will be used to as the root's
- * {@link FacetResultNode} label.
- */
- @SuppressWarnings("unchecked")
- public RangeFacetRequest(String field, List<T> ranges) {
- this(field, (T[]) ranges.toArray(new Range[ranges.size()]));
- }
-
- /**
- * Create a request for the given ranges over the specified
- * {@link ValueSource}. The label will be used to as the root's
- * {@link FacetResultNode} label.
- */
- @SuppressWarnings("unchecked")
- public RangeFacetRequest(String label, ValueSource valueSource, T...ranges) {
- super(new FacetLabel(label), 1);
- this.ranges = ranges;
- this.valueSource = valueSource;
- this.label = label;
- }
-
- /**
- * Create a request for the given ranges over the specified
- * {@link ValueSource}. The label will be used to as the root's
- * {@link FacetResultNode} label.
- */
- @SuppressWarnings("unchecked")
- public RangeFacetRequest(String label, ValueSource valueSource, List<T> ranges) {
- this(label, valueSource, (T[]) ranges.toArray(new Range[ranges.size()]));
- }
-
- /**
- * Returns the {@link FunctionValues} for the given
- * {@link AtomicReaderContext}. If the request was created over a
- * {@link NumericDocValues} field, the respective {@link NumericDocValues} is
- * returned.
- */
- public FunctionValues getValues(AtomicReaderContext context) throws IOException {
- return valueSource.getValues(Collections.emptyMap(), context);
- }
-
- @Override
- public FacetsAggregator createFacetsAggregator(FacetIndexingParams fip) {
- throw new UnsupportedOperationException("this FacetRequest does not support categories aggregation and only works with RangeAccumulator");
- }
-
-}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/FacetRequest.java b/lucene/facet/src/java/org/apache/lucene/facet/search/FacetRequest.java
index 5b4af6b3ba9..687e7e1d61e 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/search/FacetRequest.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/search/FacetRequest.java
@@ -2,7 +2,6 @@ package org.apache.lucene.facet.search;
import org.apache.lucene.facet.params.CategoryListParams.OrdinalPolicy;
import org.apache.lucene.facet.params.FacetIndexingParams;
-import org.apache.lucene.facet.range.RangeFacetRequest;
import org.apache.lucene.facet.taxonomy.FacetLabel;
/*
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/FacetsAccumulator.java b/lucene/facet/src/java/org/apache/lucene/facet/search/FacetsAccumulator.java
index 1488cdedec0..47d9885b377 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/search/FacetsAccumulator.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/search/FacetsAccumulator.java
@@ -7,8 +7,6 @@ import java.util.List;
import org.apache.lucene.facet.old.OldFacetsAccumulator;
import org.apache.lucene.facet.params.FacetIndexingParams;
import org.apache.lucene.facet.params.FacetSearchParams;
-import org.apache.lucene.facet.range.RangeAccumulator;
-import org.apache.lucene.facet.range.RangeFacetRequest;
import org.apache.lucene.facet.search.FacetsCollector.MatchingDocs;
import org.apache.lucene.facet.sortedset.SortedSetDocValuesAccumulator;
import org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState;
@@ -76,26 +74,7 @@ public abstract class FacetsAccumulator {
return new OldFacetsAccumulator(fsp, indexReader, taxoReader, arrays);
}
- List<FacetRequest> rangeRequests = new ArrayList<FacetRequest>();
- List<FacetRequest> nonRangeRequests = new ArrayList<FacetRequest>();
- for (FacetRequest fr : fsp.facetRequests) {
- if (fr instanceof RangeFacetRequest) {
- rangeRequests.add(fr);
- } else {
- nonRangeRequests.add(fr);
- }
- }
-
- if (rangeRequests.isEmpty()) {
- return new TaxonomyFacetsAccumulator(fsp, indexReader, taxoReader, arrays);
- } else if (nonRangeRequests.isEmpty()) {
- return new RangeAccumulator(rangeRequests);
- } else {
- FacetSearchParams searchParams = new FacetSearchParams(fsp.indexingParams, nonRangeRequests);
- FacetsAccumulator accumulator = new TaxonomyFacetsAccumulator(searchParams, indexReader, taxoReader, arrays);
- RangeAccumulator rangeAccumulator = new RangeAccumulator(rangeRequests);
- return MultiFacetsAccumulator.wrap(accumulator, rangeAccumulator);
- }
+ return new TaxonomyFacetsAccumulator(fsp, indexReader, taxoReader, arrays);
}
/**
@@ -124,26 +103,7 @@ public abstract class FacetsAccumulator {
throw new IllegalArgumentException("only default partition size is supported by this method: " + fsp.indexingParams.getPartitionSize());
}
- List<FacetRequest> rangeRequests = new ArrayList<FacetRequest>();
- List<FacetRequest> nonRangeRequests = new ArrayList<FacetRequest>();
- for (FacetRequest fr : fsp.facetRequests) {
- if (fr instanceof RangeFacetRequest) {
- rangeRequests.add(fr);
- } else {
- nonRangeRequests.add(fr);
- }
- }
-
- if (rangeRequests.isEmpty()) {
- return new SortedSetDocValuesAccumulator(state, fsp, arrays);
- } else if (nonRangeRequests.isEmpty()) {
- return new RangeAccumulator(rangeRequests);
- } else {
- FacetSearchParams searchParams = new FacetSearchParams(fsp.indexingParams, nonRangeRequests);
- FacetsAccumulator accumulator = new SortedSetDocValuesAccumulator(state, searchParams, arrays);
- RangeAccumulator rangeAccumulator = new RangeAccumulator(rangeRequests);
- return MultiFacetsAccumulator.wrap(accumulator, rangeAccumulator);
- }
+ return new SortedSetDocValuesAccumulator(state, fsp, arrays);
}
/** Returns an empty {@link FacetResult}. */