CavalliumDBEngine/src/main/java/it/cavallium/dbengine/client/MultiSort.java

78 lines
2.3 KiB
Java
Raw Normal View History

2021-02-03 20:13:17 +01:00
package it.cavallium.dbengine.client;
2021-07-17 23:06:26 +02:00
import it.cavallium.dbengine.client.query.current.data.NoSort;
2021-03-02 01:53:36 +01:00
import it.cavallium.dbengine.client.query.current.data.NumericSort;
import it.cavallium.dbengine.client.query.current.data.RandomSort;
import it.cavallium.dbengine.client.query.current.data.ScoreSort;
import it.cavallium.dbengine.client.query.current.data.Sort;
import it.cavallium.dbengine.database.LLKeyScore;
2021-02-03 20:13:17 +01:00
import java.util.Comparator;
import java.util.function.Function;
2021-02-03 20:13:17 +01:00
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
import org.jetbrains.annotations.NotNull;
import reactor.core.publisher.Mono;
2021-02-03 20:13:17 +01:00
public class MultiSort<T> {
2021-02-03 20:13:17 +01:00
2021-03-02 01:53:36 +01:00
private final Sort querySort;
2021-02-03 20:13:17 +01:00
public MultiSort(Sort querySort) {
2021-02-03 20:13:17 +01:00
this.querySort = querySort;
}
/**
* Sort a lucene field and the results by a numeric sort field and an int value
* @param fieldName Lucene SortedNumericSortField field name
* @param reverse descending sort
* @param <T> result type
* @return MultiSort object
*/
public static <T> MultiSort<T> sortedNumericInt(String fieldName, boolean reverse) {
2021-02-03 20:13:17 +01:00
// Create lucene sort
2021-03-02 01:53:36 +01:00
Sort querySort = NumericSort.of(fieldName, reverse);
2021-02-03 20:13:17 +01:00
// Return the multi sort
return new MultiSort<>(querySort);
2021-02-03 20:13:17 +01:00
}
/**
* Sort a lucene field and the results by a numeric sort field and an long value
* @param fieldName Lucene SortedNumericSortField field name
* @param reverse descending sort
* @param <T> result type
* @return MultiSort object
*/
public static <T> MultiSort<T> sortedNumericLong(String fieldName, boolean reverse) {
2021-02-03 20:13:17 +01:00
// Create lucene sort
2021-03-02 01:53:36 +01:00
Sort querySort = NumericSort.of(fieldName, reverse);
2021-02-03 20:13:17 +01:00
// Return the multi sort
return new MultiSort<>(querySort);
2021-02-03 20:13:17 +01:00
}
public static <T> MultiSort<T> randomSortField() {
return new MultiSort<>(RandomSort.of());
2021-02-03 20:13:17 +01:00
}
public static MultiSort<LLKeyScore> topScoreRaw() {
return new MultiSort<>(ScoreSort.of());
}
public static <T> MultiSort<SearchResultKey<T>> topScore() {
return new MultiSort<>(ScoreSort.of());
2021-02-03 20:13:17 +01:00
}
public static <T, U> MultiSort<SearchResultItem<T, U>> topScoreWithValues() {
return new MultiSort<>(ScoreSort.of());
2021-02-03 20:13:17 +01:00
}
2021-07-17 23:06:26 +02:00
public static <T, U> MultiSort<SearchResultItem<T, U>> noScoreNoSortWithValues() {
return new MultiSort<>(NoSort.of());
}
2021-03-02 01:53:36 +01:00
public Sort getQuerySort() {
2021-02-03 20:13:17 +01:00
return querySort;
}
}