Package org.apache.lucene.sandbox.facet

# Class ComparableUtils

java.lang.Object
org.apache.lucene.sandbox.facet.ComparableUtils

public final class ComparableUtils extends Object
Collection of static methods to provide most common comparables for sandbox faceting. You can also use it as an example for creating your own `ComparableSupplier` to enable custom facets top-n and sorting.

WARNING: This API is experimental and might change in incompatible ways in the next release.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`ComparableUtils.ByAggregatedValueComparable`
Used for `byAggregatedValue(org.apache.lucene.sandbox.facet.recorders.CountFacetRecorder, org.apache.lucene.sandbox.facet.recorders.LongAggregationsFacetRecorder, int)` result.
`static class`
`ComparableUtils.ByCountAndLongValueComparable`
Used for `byCount(CountFacetRecorder, LongValueFacetCutter)` result.
`static class`
`ComparableUtils.ByCountComparable`
Used for `byCount(org.apache.lucene.sandbox.facet.recorders.CountFacetRecorder)` result.
`static final class`
`ComparableUtils.ByLongValueComparable`
Used for `byLongValue(org.apache.lucene.sandbox.facet.cutters.LongValueFacetCutter)` result.
`static class`
`ComparableUtils.ByOrdinalComparable`
Used for `byOrdinal()` result.

## Method Summary

Modifier and Type
Method
Description
`static ComparableSupplier<ComparableUtils.ByAggregatedValueComparable>`
`byAggregatedValue(CountFacetRecorder countRecorder, LongAggregationsFacetRecorder longAggregationsFacetRecorder, int aggregationId)`
`ComparableSupplier` to sort ordinals by long aggregation (descending) with tie-break by count (descending) or by ordinal (ascending) using provided `CountFacetRecorder` and `LongAggregationsFacetRecorder`.
`static ComparableSupplier<ComparableUtils.ByCountComparable>`
`byCount(CountFacetRecorder recorder)`
`ComparableSupplier` to sort ordinals by count (descending) with ord as a tie-break (ascending) using provided `CountFacetRecorder`.
`static ComparableSupplier<ComparableUtils.ByCountAndLongValueComparable>`
`byCount(CountFacetRecorder countFacetRecorder, LongValueFacetCutter longValueFacetCutter)`
`ComparableSupplier` to sort ordinals by count (descending) from `CountFacetRecorder` with tie-break by long value (ascending) from `LongValueFacetCutter`.
`static ComparableSupplier<ComparableUtils.ByLongValueComparable>`
`byLongValue(LongValueFacetCutter longValueFacetCutter)`
`ComparableSupplier` to sort ordinals by long value from `LongValueFacetCutter` (descending).
`static ComparableSupplier<ComparableUtils.ByOrdinalComparable>`
`byOrdinal()`
`ComparableSupplier` to sort by ords (ascending).
`static <T extends Comparable<T>>
void`
`sort(int[] ordinals, ComparableSupplier<T> comparableSupplier)`
Sort array of ordinals.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### byOrdinal

public static ComparableSupplier<ComparableUtils.ByOrdinalComparable> byOrdinal()
`ComparableSupplier` to sort by ords (ascending).

### byCount

public static ComparableSupplier<ComparableUtils.ByCountComparable> byCount(CountFacetRecorder recorder)
`ComparableSupplier` to sort ordinals by count (descending) with ord as a tie-break (ascending) using provided `CountFacetRecorder`.

### byAggregatedValue

public static ComparableSupplier<ComparableUtils.ByAggregatedValueComparable> byAggregatedValue(CountFacetRecorder countRecorder, LongAggregationsFacetRecorder longAggregationsFacetRecorder, int aggregationId)
`ComparableSupplier` to sort ordinals by long aggregation (descending) with tie-break by count (descending) or by ordinal (ascending) using provided `CountFacetRecorder` and `LongAggregationsFacetRecorder`.

### byLongValue

public static ComparableSupplier<ComparableUtils.ByLongValueComparable> byLongValue(LongValueFacetCutter longValueFacetCutter)
`ComparableSupplier` to sort ordinals by long value from `LongValueFacetCutter` (descending).

### byCount

public static ComparableSupplier<ComparableUtils.ByCountAndLongValueComparable> byCount(CountFacetRecorder countFacetRecorder, LongValueFacetCutter longValueFacetCutter)
`ComparableSupplier` to sort ordinals by count (descending) from `CountFacetRecorder` with tie-break by long value (ascending) from `LongValueFacetCutter`.

### sort

public static <T extends Comparable<T>> void sort(int[] ordinals, ComparableSupplier<T> comparableSupplier) throws IOException
Sort array of ordinals.

To get top-n ordinals use `TopnOrdinalIterator` instead.

Parameters:
  `ordinals` - array of ordinals to sort
  `comparableSupplier` - defines sort order
Throws:
  `IOException`