Apache Solr open-source search software
LUCENE-4759: remove FacetRequest.SortBy
Shai Ererafbfeca05cdd7
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex d9413329339..3dfeed1234c 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -69,6 +69,9 @@ Changes in backwards compatibility policy* LUCENE-4750: Convert DrillDown to DrillDownQuery, so you can initialize itand add drill-down categories to it. (Michael McCandless, Shai Erera)+* LUCENE-4759: remove FacetRequest.SortBy; result categories are always+ sorted by value, while ties are broken by category ordinal. (Shai Erera)+Optimizations* LUCENE-4687: BloomFilterPostingsFormat now lazily initializes delegatediff --git a/lucene/facet/src/java/org/apache/lucene/facet/sampling/Sampler.java b/lucene/facet/src/java/org/apache/lucene/facet/sampling/Sampler.javaindex 7a8f4ea9443..85306b4f73c 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/sampling/Sampler.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/sampling/Sampler.java@@ -222,7 +222,6 @@ public abstract class Sampler {setDepth(orig.getDepth());setNumLabel(orig.getNumLabel());setResultMode(orig.getResultMode());- setSortBy(orig.getSortBy());setSortOrder(orig.getSortOrder());}diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/DepthOneFacetResultsHandler.java b/lucene/facet/src/java/org/apache/lucene/facet/search/DepthOneFacetResultsHandler.javaindex 439b37582d4..0839bc3f72b 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/search/DepthOneFacetResultsHandler.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/search/DepthOneFacetResultsHandler.java@@ -6,7 +6,6 @@ import java.util.Arrays;import java.util.Collections;import java.util.Comparator;-import org.apache.lucene.facet.search.FacetRequest.SortBy;import org.apache.lucene.facet.search.FacetRequest.SortOrder;import org.apache.lucene.facet.taxonomy.TaxonomyReader;import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;@@ -65,7 +64,6 @@ public abstract class DepthOneFacetResultsHandler extends FacetResultsHandler {assert facetRequest.getDepth() == 1 : "this handler only computes the top-K facets at depth 1";assert facetRequest.numResults == facetRequest.getNumLabel() : "this handler always labels all top-K results";assert facetRequest.getSortOrder() == SortOrder.DESCENDING : "this handler always sorts results in descending order";- assert facetRequest.getSortBy() == SortBy.VALUE : "this handler always sorts results by value";}/** Returnt the value of the requested ordinal. Called once for the result root. */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.javaindex 867316483b2..1460da505d6 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@@ -63,15 +63,6 @@ public abstract class FacetRequest {*/public enum FacetArraysSource { INT, FLOAT, BOTH }- /** Sort options for facet results. */- public enum SortBy {- /** sort by category ordinal with the taxonomy */- ORDINAL,-- /** sort by computed category value */- VALUE- }-/** Requested sort order for the results. */public enum SortOrder { ASCENDING, DESCENDING }@@ -81,12 +72,6 @@ public abstract class FacetRequest {*/public static final int DEFAULT_DEPTH = 1;- /**- * Default sort mode.- * @see #getSortBy()- */- public static final SortBy DEFAULT_SORT_BY = SortBy.VALUE;-/*** Default result mode* @see #getResultMode()@@ -99,7 +84,6 @@ public abstract class FacetRequest {private int numLabel;private int depth;private SortOrder sortOrder;- private SortBy sortBy;/*** Computed at construction, this hashCode is based on two final members@@ -135,7 +119,6 @@ public abstract class FacetRequest {this.numResults = numResults;numLabel = numResults;depth = DEFAULT_DEPTH;- sortBy = DEFAULT_SORT_BY;sortOrder = SortOrder.DESCENDING;hashCode = categoryPath.hashCode() ^ this.numResults;@@ -221,11 +204,6 @@ public abstract class FacetRequest {return resultMode;}- /** Specify how should results be sorted. */- public final SortBy getSortBy() {- return sortBy;- }-/** Return the requested order of results. */public final SortOrder getSortOrder() {return sortOrder;@@ -276,10 +254,6 @@ public abstract class FacetRequest {this.resultMode = resultMode;}- public void setSortBy(SortBy sortBy) {- this.sortBy = sortBy;- }-public void setSortOrder(SortOrder sortOrder) {this.sortOrder = sortOrder;}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.javaindex b0220e1baf0..207f4b0ed09 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@@ -13,7 +13,6 @@ import org.apache.lucene.facet.params.FacetSearchParams;import org.apache.lucene.facet.params.CategoryListParams.OrdinalPolicy;import org.apache.lucene.facet.search.FacetRequest.FacetArraysSource;import org.apache.lucene.facet.search.FacetRequest.ResultMode;-import org.apache.lucene.facet.search.FacetRequest.SortBy;import org.apache.lucene.facet.search.FacetRequest.SortOrder;import org.apache.lucene.facet.search.FacetsCollector.MatchingDocs;import org.apache.lucene.facet.taxonomy.TaxonomyReader;@@ -99,7 +98,7 @@ public class FacetsAccumulator {* {@link FacetRequest}.*/protected FacetResultsHandler createFacetResultsHandler(FacetRequest fr) {- if (fr.getDepth() == 1 && fr.getSortOrder() == SortOrder.DESCENDING && fr.getSortBy() == SortBy.VALUE) {+ if (fr.getDepth() == 1 && fr.getSortOrder() == SortOrder.DESCENDING) {FacetArraysSource fas = fr.getFacetArraysSource();if (fas == FacetArraysSource.INT) {return new IntFacetResultsHandler(taxonomyReader, fr, facetArrays);diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java b/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.javaindex 3b5f1c95c83..05bebcb1ac0 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java@@ -38,12 +38,8 @@ import org.apache.lucene.util.PriorityQueue;* {@link FacetRequest#categoryPath}, and the enumerated children,* {@link FacetResultNode#subResults}, of each node in that {@link FacetResult}* are the top K ( = {@link FacetRequest#numResults}) among its children in the- * taxonomy. Top in the sense {@link FacetRequest#getSortBy()}, which can be by- * the values aggregated in the count arrays, or by ordinal numbers; also- * specified is the sort order, {@link FacetRequest#getSortOrder()}, ascending- * or descending, of these values or ordinals before their top K are selected.- * The depth (number of levels excluding the root) of the {@link FacetResult}- * tree is specified by {@link FacetRequest#getDepth()}.+ * taxonomy. The depth (number of levels excluding the root) of the+ * {@link FacetResult} tree is specified by {@link FacetRequest#getDepth()}.* <p>* Because the number of selected children of each node is restricted, and not* the overall number of nodes in the {@link FacetResult}, facets not selected@@ -536,21 +532,10 @@ public class TopKInEachNodeHandler extends PartitionsFacetResultsHandler {private ACComparator getSuitableACComparator() {if (facetRequest.getSortOrder() == SortOrder.ASCENDING) {- switch (facetRequest.getSortBy()) {- case VALUE:- return new AscValueACComparator();- case ORDINAL:- return new AscOrdACComparator();- }+ return new AscValueACComparator();} else {- switch (facetRequest.getSortBy()) {- case VALUE:- return new DescValueACComparator();- case ORDINAL:- return new DescOrdACComparator();- }+ return new DescValueACComparator();}- return null;}/**@@ -584,26 +569,6 @@ public class TopKInEachNodeHandler extends PartitionsFacetResultsHandler {}}- private static final class AscOrdACComparator extends ACComparator {-- AscOrdACComparator() { }-- @Override- protected boolean leftGoesNow (int ord1, double val1, int ord2, double val2) {- return (ord1 < ord2);- }- }-- private static final class DescOrdACComparator extends ACComparator {-- DescOrdACComparator() { }-- @Override- protected boolean leftGoesNow (int ord1, double val1, int ord2, double val2) {- return (ord1 > ord2);- }- }-/*** Intermediate result to hold counts from one or more partitions processed* thus far. Its main field, constructor parameter <i>mapToAACOs</i>, is a mapdiff --git a/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java b/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.javaindex 7a328a6006c..1b11244cc53 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java@@ -49,21 +49,10 @@ public class ResultSortUtils {}if (accending) {- switch (facetRequest.getSortBy()) {- case VALUE:- return new MaxValueHeap(nresults);- case ORDINAL:- return new MaxOrdinalHeap(nresults);- }+ return new MaxValueHeap(nresults);} else {- switch (facetRequest.getSortBy()) {- case VALUE:- return new MinValueHeap(nresults);- case ORDINAL:- return new MinOrdinalHeap(nresults);- }+ return new MinValueHeap(nresults);}- throw new IllegalArgumentException("none supported facet request: "+facetRequest);}private static class MinValueHeap extends PriorityQueue<FacetResultNode> implements Heap<FacetResultNode> {@@ -105,30 +94,6 @@ public class ResultSortUtils {}}- private static class MinOrdinalHeap extends PriorityQueue<FacetResultNode> implements Heap<FacetResultNode> {- public MinOrdinalHeap(int size) {- super(size);- }-- @Override- protected boolean lessThan(FacetResultNode arg0, FacetResultNode arg1) {- return arg0.ordinal < arg1.ordinal;- }-- }-- private static class MaxOrdinalHeap extends PriorityQueue<FacetResultNode> implements Heap<FacetResultNode> {- public MaxOrdinalHeap(int size) {- super(size);- }-- @Override- protected boolean lessThan(FacetResultNode arg0, FacetResultNode arg1) {- return arg0.ordinal > arg1.ordinal;- }-- }-/*** Create a Heap-Look-Alike, which implements {@link Heap}, but uses a* regular <code>ArrayList</code> for holding <b>ALL</b> the objects given,