Fix assertions
This commit is contained in:
parent
f6aab7dafb
commit
fd565c80b2
@ -15,6 +15,7 @@ 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;
|
||||
@ -82,9 +83,10 @@ public class OfficialSearcher implements MultiSearcher, Closeable {
|
||||
|
||||
var collector = sharedManager.newCollector();
|
||||
assert queryParams.complete() == collector.scoreMode().isExhaustive();
|
||||
queryParams.getScoreModeOptional().ifPresent(scoreMode -> {
|
||||
assert scoreMode == collector.scoreMode();
|
||||
});
|
||||
assert queryParams
|
||||
.getScoreModeOptional()
|
||||
.map(scoreMode -> scoreMode == collector.scoreMode())
|
||||
.orElse(true);
|
||||
|
||||
shard.search(queryParams.query(), collector);
|
||||
return collector;
|
||||
|
@ -18,6 +18,7 @@ import java.util.Objects;
|
||||
import org.apache.lucene.search.Collector;
|
||||
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;
|
||||
@ -188,9 +189,10 @@ public class PagedLocalSearcher implements LocalSearcher {
|
||||
currentPageLimit, s.last(), queryParams.getTotalHitsThresholdInt(),
|
||||
allowPagination, queryParams.needsScores());
|
||||
assert queryParams.complete() == collector.scoreMode().isExhaustive();
|
||||
queryParams.getScoreModeOptional().ifPresent(scoreMode -> {
|
||||
assert scoreMode == collector.scoreMode();
|
||||
});
|
||||
assert currentPageLimit < Integer.MAX_VALUE || queryParams
|
||||
.getScoreModeOptional()
|
||||
.map(scoreMode -> scoreMode == collector.scoreMode())
|
||||
.orElse(true);
|
||||
|
||||
indexSearchers.get(0).search(queryParams.query(), collector);
|
||||
if (resultsOffset > 0) {
|
||||
|
@ -15,6 +15,7 @@ import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.apache.lucene.search.FieldDoc;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.ScoreMode;
|
||||
import org.apache.lucene.search.Sort;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.warp.commonutils.log.Logger;
|
||||
@ -188,9 +189,10 @@ public class ScoredPagedMultiSearcher implements MultiSearcher {
|
||||
|
||||
var collector = sharedManager.newCollector();
|
||||
assert queryParams.complete() == collector.scoreMode().isExhaustive();
|
||||
queryParams.getScoreModeOptional().ifPresent(scoreMode -> {
|
||||
assert scoreMode == collector.scoreMode();
|
||||
});
|
||||
assert pageLimits.getPageLimit(s.pageIndex()) < Integer.MAX_VALUE || queryParams
|
||||
.getScoreModeOptional()
|
||||
.map(scoreMode -> scoreMode == collector.scoreMode())
|
||||
.orElse(true);
|
||||
|
||||
shard.search(queryParams.query(), collector);
|
||||
return collector;
|
||||
|
@ -73,9 +73,10 @@ public class SortedScoredFullMultiSearcher implements MultiSearcher, Closeable {
|
||||
|
||||
var collector = sharedManager.newCollector();
|
||||
assert queryParams.complete() == collector.scoreMode().isExhaustive();
|
||||
queryParams.getScoreModeOptional().ifPresent(scoreMode -> {
|
||||
assert scoreMode == collector.scoreMode();
|
||||
});
|
||||
assert queryParams
|
||||
.getScoreModeOptional()
|
||||
.map(scoreMode -> scoreMode == collector.scoreMode())
|
||||
.orElse(true);
|
||||
|
||||
shard.search(queryParams.query(), collector);
|
||||
return collector;
|
||||
|
@ -79,9 +79,10 @@ public class UnsortedScoredFullMultiSearcher implements MultiSearcher, Closeable
|
||||
|
||||
var collector = sharedManager.newCollector();
|
||||
assert queryParams.complete() == collector.scoreMode().isExhaustive();
|
||||
queryParams.getScoreModeOptional().ifPresent(scoreMode -> {
|
||||
assert scoreMode == collector.scoreMode();
|
||||
});
|
||||
assert queryParams
|
||||
.getScoreModeOptional()
|
||||
.map(scoreMode -> scoreMode == collector.scoreMode())
|
||||
.orElse(true);
|
||||
|
||||
shard.search(queryParams.query(), collector);
|
||||
return collector;
|
||||
|
@ -76,9 +76,10 @@ public class UnsortedUnscoredStreamingMultiSearcher implements MultiSearcher {
|
||||
try {
|
||||
var collector = cm.newCollector();
|
||||
assert queryParams.complete() == collector.scoreMode().isExhaustive();
|
||||
queryParams.getScoreModeOptional().ifPresent(scoreMode -> {
|
||||
assert scoreMode == collector.scoreMode();
|
||||
});
|
||||
assert queryParams
|
||||
.getScoreModeOptional()
|
||||
.map(scoreMode -> scoreMode == collector.scoreMode())
|
||||
.orElse(true);
|
||||
|
||||
collector.setShardIndex(shardIndex);
|
||||
|
||||
|
@ -18,10 +18,17 @@ import it.cavallium.dbengine.client.query.BasicType;
|
||||
import it.cavallium.dbengine.client.query.ClientQueryParams;
|
||||
import it.cavallium.dbengine.client.query.ClientQueryParamsBuilder;
|
||||
import it.cavallium.dbengine.client.query.QueryParser;
|
||||
import it.cavallium.dbengine.client.query.current.data.BooleanQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.BooleanQueryPart;
|
||||
import it.cavallium.dbengine.client.query.current.data.BoostQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.MatchAllDocsQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.MatchNoDocsQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.NoSort;
|
||||
import it.cavallium.dbengine.client.query.current.data.OccurMust;
|
||||
import it.cavallium.dbengine.client.query.current.data.OccurShould;
|
||||
import it.cavallium.dbengine.client.query.current.data.ScoreSort;
|
||||
import it.cavallium.dbengine.client.query.current.data.Term;
|
||||
import it.cavallium.dbengine.client.query.current.data.TermQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
|
||||
import it.cavallium.dbengine.database.LLLuceneIndex;
|
||||
import it.cavallium.dbengine.database.LLScoreMode;
|
||||
@ -321,18 +328,27 @@ public class TestLuceneSearches {
|
||||
testSearch(queryBuilder, expectedQueryType);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideQueryArgumentsScoreModeAndSort")
|
||||
public void testSearchAdvancedText(boolean shards, MultiSort<SearchResultKey<String>> multiSort) throws Throwable {
|
||||
var queryBuilder = ClientQueryParams
|
||||
.<SearchResultKey<String>>builder()
|
||||
.query(new BooleanQuery(List.of(
|
||||
new BooleanQueryPart(new BoostQuery(new TermQuery(new Term("text", "hello")), 3), new OccurShould()),
|
||||
new BooleanQueryPart(new TermQuery(new Term("text", "world")), new OccurShould()),
|
||||
new BooleanQueryPart(new BoostQuery(new TermQuery(new Term("text", "hello")), 2), new OccurShould()),
|
||||
new BooleanQueryPart(new BoostQuery(new TermQuery(new Term("text", "hello")), 100), new OccurShould()),
|
||||
new BooleanQueryPart(new TermQuery(new Term("text", "hello")), new OccurMust())
|
||||
), 1))
|
||||
.snapshot(null)
|
||||
.complete(true)
|
||||
.sort(multiSort);
|
||||
|
||||
ExpectedQueryType expectedQueryType = new ExpectedQueryType(shards, multiSort, true, false);
|
||||
testSearch(queryBuilder, expectedQueryType);
|
||||
}
|
||||
|
||||
private void assertResults(List<Scored> expectedKeys, List<Scored> resultKeys, boolean sorted, boolean sortedByScore) {
|
||||
|
||||
if (sortedByScore) {
|
||||
float lastScore = Float.NEGATIVE_INFINITY;
|
||||
for (Scored resultKey : resultKeys) {
|
||||
if (!Float.isNaN(resultKey.score())) {
|
||||
Assertions.assertTrue(resultKey.score() >= lastScore);
|
||||
lastScore = resultKey.score();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sortedByScore) {
|
||||
Assertions.assertEquals(expectedKeys, resultKeys);
|
||||
} else if (sorted) {
|
||||
|
Loading…
Reference in New Issue
Block a user