Rename unclear parameters

This commit is contained in:
Andrea Cavalli 2021-11-16 23:54:23 +01:00
parent c1c57388e5
commit e014266b8d
11 changed files with 33 additions and 86 deletions

View File

@ -189,7 +189,7 @@ versions:
limit: long
minCompetitiveScore: -float
sort: Sort
complete: boolean
computePreciseHitsCount: boolean
NoSort:
data: { }
NumericSort:

View File

@ -18,7 +18,7 @@ public final record ClientQueryParams(@Nullable CompositeSnapshot snapshot,
long limit,
@Nullable Float minCompetitiveScore,
@Nullable Sort sort,
boolean complete) {
boolean computePreciseHitsCount) {
public static ClientQueryParamsBuilder builder() {
return ClientQueryParamsBuilder
@ -28,7 +28,7 @@ public final record ClientQueryParams(@Nullable CompositeSnapshot snapshot,
.limit(Long.MAX_VALUE)
.minCompetitiveScore(null)
.sort(null)
.complete(true);
.computePreciseHitsCount(true);
}
public boolean isSorted() {
@ -43,7 +43,7 @@ public final record ClientQueryParams(@Nullable CompositeSnapshot snapshot,
.minCompetitiveScore(Nullablefloat.ofNullable(minCompetitiveScore()))
.offset(offset())
.limit(limit())
.complete(complete())
.computePreciseHitsCount(computePreciseHitsCount())
.build();
}
}

View File

@ -26,7 +26,6 @@ import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -347,7 +346,7 @@ public class LuceneUtils {
DEFAULT_PAGE_LIMITS,
queryParams.minCompetitiveScore().getNullable(),
QueryParser.toSort(queryParams.sort()),
queryParams.complete()
queryParams.computePreciseHitsCount()
);
}
@ -502,7 +501,7 @@ public class LuceneUtils {
DEFAULT_PAGE_LIMITS,
localQueryParams.minCompetitiveScore(),
localQueryParams.sort(),
localQueryParams.complete()
localQueryParams.computePreciseHitsCount()
);
}
MultiMoreLikeThis mlt;
@ -547,7 +546,7 @@ public class LuceneUtils {
DEFAULT_PAGE_LIMITS,
localQueryParams.minCompetitiveScore(),
localQueryParams.sort(),
localQueryParams.complete()
localQueryParams.computePreciseHitsCount()
);
}).subscribeOn(Schedulers.boundedElastic()));
}

View File

@ -92,7 +92,7 @@ public class CountMultiSearcher implements MultiSearcher {
queryParams.pageLimits(),
queryParams.minCompetitiveScore(),
queryParams.sort(),
queryParams.complete()
queryParams.computePreciseHitsCount()
);
}

View File

@ -5,16 +5,14 @@ import static it.cavallium.dbengine.lucene.LuceneUtils.safeLongToInt;
import it.cavallium.dbengine.lucene.LuceneUtils;
import it.cavallium.dbengine.lucene.PageLimits;
import java.util.Objects;
import java.util.Optional;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Sort;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public record LocalQueryParams(@NotNull Query query, int offsetInt, long offsetLong, int limitInt, long limitLong,
@NotNull PageLimits pageLimits,
@Nullable Float minCompetitiveScore, @Nullable Sort sort, boolean complete) {
@Nullable Float minCompetitiveScore, @Nullable Sort sort, boolean computePreciseHitsCount) {
public LocalQueryParams(@NotNull Query query,
long offsetLong,
@ -22,9 +20,9 @@ public record LocalQueryParams(@NotNull Query query, int offsetInt, long offsetL
@NotNull PageLimits pageLimits,
@Nullable Float minCompetitiveScore,
@Nullable Sort sort,
boolean complete) {
boolean computePreciseHitsCount) {
this(query, safeLongToInt(offsetLong), offsetLong, safeLongToInt(limitLong), limitLong, pageLimits,
minCompetitiveScore, sort, complete);
minCompetitiveScore, sort, computePreciseHitsCount);
}
public LocalQueryParams(@NotNull Query query,
@ -33,8 +31,17 @@ public record LocalQueryParams(@NotNull Query query, int offsetInt, long offsetL
@NotNull PageLimits pageLimits,
@Nullable Float minCompetitiveScore,
@Nullable Sort sort,
boolean complete) {
this(query, offsetInt, offsetInt, limitInt, limitInt, pageLimits, minCompetitiveScore, sort, complete);
boolean computePreciseHitsCount) {
this(query,
offsetInt,
offsetInt,
limitInt,
limitInt,
pageLimits,
minCompetitiveScore,
sort,
computePreciseHitsCount
);
}
public boolean isSorted() {
@ -49,32 +56,11 @@ public record LocalQueryParams(@NotNull Query query, int offsetInt, long offsetL
return sort != null && sort.needsScores();
}
public Optional<Boolean> needsScoresOptional() {
if (sort == null) return Optional.empty();
return Optional.of(sort.needsScores());
}
public ScoreMode getScoreMode() {
if (complete) {
return needsScores() ? ScoreMode.COMPLETE : ScoreMode.COMPLETE_NO_SCORES;
} else {
return needsScores() ? ScoreMode.TOP_DOCS_WITH_SCORES : ScoreMode.TOP_DOCS;
}
}
public Optional<ScoreMode> getScoreModeOptional() {
if (complete) {
return needsScoresOptional().map(needsScores -> needsScores ? ScoreMode.COMPLETE : ScoreMode.COMPLETE_NO_SCORES);
} else {
return needsScoresOptional().map(needsScores -> needsScores ? ScoreMode.TOP_DOCS_WITH_SCORES : ScoreMode.TOP_DOCS);
}
}
public int getTotalHitsThresholdInt() {
return LuceneUtils.totalHitsThreshold(this.complete);
return LuceneUtils.totalHitsThreshold(this.computePreciseHitsCount);
}
public long getTotalHitsThresholdLong() {
return LuceneUtils.totalHitsThresholdLong(this.complete);
return LuceneUtils.totalHitsThresholdLong(this.computePreciseHitsCount);
}
}

View File

@ -5,19 +5,11 @@ import it.cavallium.dbengine.database.LLKeyScore;
import it.cavallium.dbengine.database.LLUtils;
import it.cavallium.dbengine.database.disk.LLIndexSearchers;
import it.cavallium.dbengine.database.disk.LLTempLMDBEnv;
import it.cavallium.dbengine.lucene.FullDocs;
import it.cavallium.dbengine.lucene.LLFieldDoc;
import it.cavallium.dbengine.lucene.LuceneUtils;
import it.cavallium.dbengine.lucene.collector.LMDBFullFieldDocCollector;
import it.cavallium.dbengine.lucene.searcher.LLSearchTransformer.TransformerInput;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopDocsCollector;
import org.apache.lucene.search.TopFieldCollector;
import org.apache.lucene.search.TopScoreDocCollector;
import org.warp.commonutils.log.Logger;
@ -82,11 +74,7 @@ public class OfficialSearcher implements MultiSearcher {
LLUtils.ensureBlocking();
var collector = sharedManager.newCollector();
assert queryParams.complete() == collector.scoreMode().isExhaustive();
assert queryParams
.getScoreModeOptional()
.map(scoreMode -> scoreMode == collector.scoreMode())
.orElse(true);
assert queryParams.computePreciseHitsCount() == collector.scoreMode().isExhaustive();
shard.search(queryParams.query(), collector);
return collector;

View File

@ -7,16 +7,10 @@ import it.cavallium.dbengine.database.disk.LLIndexSearchers;
import it.cavallium.dbengine.database.disk.LLTempLMDBEnv;
import it.cavallium.dbengine.lucene.FullDocs;
import it.cavallium.dbengine.lucene.LLFieldDoc;
import it.cavallium.dbengine.lucene.LLScoreDoc;
import it.cavallium.dbengine.lucene.LuceneUtils;
import it.cavallium.dbengine.lucene.collector.LMDBFullFieldDocCollector;
import it.cavallium.dbengine.lucene.collector.LMDBFullScoreDocCollector;
import it.cavallium.dbengine.lucene.searcher.LLSearchTransformer.TransformerInput;
import java.io.Closeable;
import java.io.IOException;
import java.util.ServiceLoader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TopFieldCollector;
import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory;
import reactor.core.publisher.Flux;
@ -74,11 +68,7 @@ public class SortedScoredFullMultiSearcher implements MultiSearcher {
LLUtils.ensureBlocking();
var collector = sharedManager.newCollector();
assert queryParams.complete() == collector.scoreMode().isExhaustive();
assert queryParams
.getScoreModeOptional()
.map(scoreMode -> scoreMode == collector.scoreMode())
.orElse(true);
assert queryParams.computePreciseHitsCount() == collector.scoreMode().isExhaustive();
shard.search(queryParams.query(), collector);
return collector;

View File

@ -10,11 +10,7 @@ import it.cavallium.dbengine.lucene.FullDocs;
import it.cavallium.dbengine.lucene.LLScoreDoc;
import it.cavallium.dbengine.lucene.collector.LMDBFullScoreDocCollector;
import it.cavallium.dbengine.lucene.searcher.LLSearchTransformer.TransformerInput;
import java.io.Closeable;
import java.io.IOException;
import java.util.Objects;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Sort;
import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory;
import reactor.core.publisher.Flux;
@ -78,11 +74,7 @@ public class UnsortedScoredFullMultiSearcher implements MultiSearcher {
LLUtils.ensureBlocking();
var collector = sharedManager.newCollector();
assert queryParams.complete() == collector.scoreMode().isExhaustive();
assert queryParams
.getScoreModeOptional()
.map(scoreMode -> scoreMode == collector.scoreMode())
.orElse(true);
assert queryParams.computePreciseHitsCount() == collector.scoreMode().isExhaustive();
shard.search(queryParams.query(), collector);
return collector;

View File

@ -8,12 +8,9 @@ import it.cavallium.dbengine.database.disk.LLIndexSearchers;
import it.cavallium.dbengine.lucene.LuceneUtils;
import it.cavallium.dbengine.lucene.collector.ReactiveCollectorMultiManager;
import it.cavallium.dbengine.lucene.searcher.LLSearchTransformer.TransformerInput;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.warp.commonutils.type.ShortNamedThreadFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink.OverflowStrategy;
import reactor.core.publisher.Mono;
@ -62,11 +59,7 @@ public class UnsortedUnscoredStreamingMultiSearcher implements MultiSearcher {
int shardIndex = mutableShardIndex++;
try {
var collector = cmm.get(shardIndex);
assert queryParams.complete() == cmm.scoreMode().isExhaustive();
assert queryParams
.getScoreModeOptional()
.map(scoreMode -> scoreMode == cmm.scoreMode())
.orElse(true);
assert queryParams.computePreciseHitsCount() == cmm.scoreMode().isExhaustive();
shard.search(localQueryParams.query(), collector);
} catch (Throwable e) {
@ -100,7 +93,7 @@ public class UnsortedUnscoredStreamingMultiSearcher implements MultiSearcher {
queryParams.pageLimits(),
queryParams.minCompetitiveScore(),
queryParams.sort(),
queryParams.complete()
queryParams.computePreciseHitsCount()
);
}

View File

@ -294,7 +294,7 @@ public class TestLuceneSearches {
.<LazyHitKey<String>>builder()
.query(new MatchNoDocsQuery())
.snapshot(null)
.complete(true)
.computePreciseHitsCount(true)
.sort(multiSort);
ExpectedQueryType expectedQueryType = new ExpectedQueryType(shards, multiSort, true, false);
@ -308,7 +308,7 @@ public class TestLuceneSearches {
.<LazyHitKey<String>>builder()
.query(new MatchAllDocsQuery())
.snapshot(null)
.complete(true)
.computePreciseHitsCount(true)
.sort(multiSort);
ExpectedQueryType expectedQueryType = new ExpectedQueryType(shards, multiSort, true, false);
@ -328,7 +328,7 @@ public class TestLuceneSearches {
new BooleanQueryPart(new TermQuery(new Term("text", "hello")), new OccurMust())
), 1))
.snapshot(null)
.complete(true)
.computePreciseHitsCount(true)
.sort(multiSort);
ExpectedQueryType expectedQueryType = new ExpectedQueryType(shards, multiSort, true, false);

View File

@ -6,7 +6,6 @@ import it.cavallium.dbengine.database.LLKeyScore;
import it.cavallium.dbengine.database.LLUtils;
import it.cavallium.dbengine.database.disk.LLIndexSearcher;
import it.cavallium.dbengine.database.disk.LLIndexSearchers;
import it.cavallium.dbengine.lucene.LuceneUtils;
import it.cavallium.dbengine.lucene.searcher.LLSearchTransformer;
import it.cavallium.dbengine.lucene.searcher.LLSearchTransformer.TransformerInput;
import it.cavallium.dbengine.lucene.searcher.LocalQueryParams;
@ -101,7 +100,7 @@ public class UnsortedUnscoredSimpleMultiSearcher implements MultiSearcher {
queryParams.pageLimits(),
queryParams.minCompetitiveScore(),
queryParams.sort(),
queryParams.complete()
queryParams.computePreciseHitsCount()
);
}