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

71 lines
2.0 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,
2021-12-12 23:40:30 +01:00
@NotNull PageLimits pageLimits, @Nullable Float minCompetitiveScore, @Nullable Sort sort,
boolean computePreciseHitsCount, Duration timeout) {
2021-10-15 22:03:53 +02:00
public LocalQueryParams(@NotNull Query query,
long offsetLong,
long limitLong,
@NotNull PageLimits pageLimits,
@Nullable Float minCompetitiveScore,
@Nullable Sort sort,
2021-12-12 23:40:30 +01:00
boolean computePreciseHitsCount,
Duration timeout) {
2021-10-15 22:03:53 +02:00
this(query, safeLongToInt(offsetLong), offsetLong, safeLongToInt(limitLong), limitLong, pageLimits,
2021-12-12 23:40:30 +01:00
minCompetitiveScore, sort, computePreciseHitsCount, timeout);
2021-10-15 22:03:53 +02:00
}
public LocalQueryParams(@NotNull Query query,
int offsetInt,
int limitInt,
@NotNull PageLimits pageLimits,
@Nullable Float minCompetitiveScore,
@Nullable Sort sort,
2021-12-12 23:40:30 +01:00
boolean computePreciseHitsCount,
Duration timeout) {
2021-11-16 23:54:23 +01:00
this(query,
offsetInt,
offsetInt,
limitInt,
limitInt,
pageLimits,
minCompetitiveScore,
sort,
2021-12-12 23:40:30 +01:00
computePreciseHitsCount,
timeout
2021-11-16 23:54:23 +01:00
);
2021-10-15 22:03:53 +02:00
}
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
}
}