CavalliumDBEngine/src/main/java/it/cavallium/dbengine/lucene/searcher/LocalQueryParams.java

105 lines
2.5 KiB
Java
Raw Normal View History

2021-07-06 01:30:37 +02:00
package it.cavallium.dbengine.lucene.searcher;
2021-10-15 22:03:53 +02:00
import static it.cavallium.dbengine.lucene.LuceneUtils.safeLongToInt;
import it.cavallium.dbengine.lucene.LuceneUtils;
import it.cavallium.dbengine.lucene.PageLimits;
2021-12-12 23:40:30 +01:00
import java.time.Duration;
2021-10-14 15:55:58 +02:00
import java.util.Objects;
2021-07-06 01:30:37 +02:00
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
2021-10-15 22:03:53 +02:00
public record LocalQueryParams(@NotNull Query query, int offsetInt, long offsetLong, int limitInt, long limitLong,
2022-02-11 21:08:23 +01:00
@NotNull PageLimits pageLimits, @Nullable Sort sort,
@Nullable Boolean computePreciseHitsCount, Duration timeout) {
2022-02-11 21:08:23 +01:00
/**
* Sorted params with long offsets
*/
2021-10-15 22:03:53 +02:00
public LocalQueryParams(@NotNull Query query,
long offsetLong,
long limitLong,
@NotNull PageLimits pageLimits,
@Nullable Sort sort,
2022-02-11 21:08:23 +01:00
@Nullable Boolean computePreciseHitsCount,
2021-12-12 23:40:30 +01:00
Duration timeout) {
2022-02-11 13:32:50 +01:00
this(query,
safeLongToInt(offsetLong),
offsetLong,
safeLongToInt(limitLong),
limitLong,
pageLimits,
sort,
computePreciseHitsCount,
timeout
);
2021-10-15 22:03:53 +02:00
}
2022-02-11 21:08:23 +01:00
/**
* Sorted params with int offsets
*/
2021-10-15 22:03:53 +02:00
public LocalQueryParams(@NotNull Query query,
int offsetInt,
int limitInt,
@NotNull PageLimits pageLimits,
@Nullable Sort sort,
2021-12-12 23:40:30 +01:00
boolean computePreciseHitsCount,
Duration timeout) {
2022-02-11 13:32:50 +01:00
this(query, offsetInt, offsetInt, limitInt, limitInt, pageLimits, sort, computePreciseHitsCount, timeout);
2021-10-15 22:03:53 +02:00
}
2022-02-11 21:08:23 +01:00
/**
* Unsorted params with int offsets
*/
public LocalQueryParams(@NotNull Query query,
int offsetInt,
int limitInt,
@NotNull PageLimits pageLimits,
Duration timeout) {
this(query, offsetInt, offsetInt, limitInt, limitInt, pageLimits, null, null, timeout);
}
/**
* Unsorted params with long offsets
*/
public LocalQueryParams(@NotNull Query query,
long offsetLong,
long limitLong,
@NotNull PageLimits pageLimits,
Duration timeout) {
this(query,
safeLongToInt(offsetLong),
offsetLong,
safeLongToInt(limitLong),
limitLong,
pageLimits,
null,
null,
timeout
);
}
public boolean isSorted() {
return sort != null;
}
2021-10-14 15:55:58 +02:00
public boolean isSortedByScore() {
return Objects.equals(sort, Sort.RELEVANCE);
}
public boolean needsScores() {
return sort != null && sort.needsScores();
}
2021-10-15 22:03:53 +02:00
public int getTotalHitsThresholdInt() {
2021-11-16 23:54:23 +01:00
return LuceneUtils.totalHitsThreshold(this.computePreciseHitsCount);
}
2021-10-15 22:03:53 +02:00
public long getTotalHitsThresholdLong() {
2021-11-16 23:54:23 +01:00
return LuceneUtils.totalHitsThresholdLong(this.computePreciseHitsCount);
2021-10-15 22:03:53 +02:00
}
}