Update tests
This commit is contained in:
parent
e6c0f14fda
commit
f91617c7ec
@ -1,3 +1,12 @@
|
|||||||
package it.cavallium.dbengine;
|
package it.cavallium.dbengine;
|
||||||
|
|
||||||
record ExpectedQueryType(boolean shard, boolean sorted, boolean sortedByScore, boolean complete, boolean onlyCount) {}
|
import it.cavallium.dbengine.client.MultiSort;
|
||||||
|
import it.cavallium.dbengine.client.SearchResultKey;
|
||||||
|
import it.cavallium.dbengine.client.query.BasicType;
|
||||||
|
|
||||||
|
record ExpectedQueryType(boolean shard, boolean sorted, boolean sortedByScore, boolean complete, boolean onlyCount) {
|
||||||
|
|
||||||
|
public ExpectedQueryType(boolean shard, MultiSort<SearchResultKey<String>> multiSort, boolean complete, boolean onlyCount) {
|
||||||
|
this(shard, multiSort.isSorted(), multiSort.getQuerySort().getBasicType$() == BasicType.ScoreSort, complete, onlyCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -251,59 +251,69 @@ public class TestLuceneSearches {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSearch(ClientQueryParamsBuilder<SearchResultKey<String>> queryParamsBuilder,
|
||||||
|
ExpectedQueryType expectedQueryType) throws Throwable {
|
||||||
|
|
||||||
|
runSearchers(expectedQueryType, searcher -> {
|
||||||
|
var luceneIndex = getLuceneIndex(expectedQueryType.shard(), searcher);
|
||||||
|
var query = queryParamsBuilder.build();
|
||||||
|
try (var results = run(luceneIndex.search(query)).receive()) {
|
||||||
|
var hits = results.totalHitsCount();
|
||||||
|
var keys = getResults(results);
|
||||||
|
if (hits.exact()) {
|
||||||
|
Assertions.assertEquals(keys.size(), hits.value());
|
||||||
|
} else {
|
||||||
|
Assertions.assertTrue(keys.size() >= hits.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
var officialSearcher = new OfficialSearcher();
|
||||||
|
luceneIndex = getLuceneIndex(expectedQueryType.shard(), officialSearcher);
|
||||||
|
var officialQuery = queryParamsBuilder.limit(ELEMENTS.size() * 2L).build();
|
||||||
|
try (var officialResults = run(luceneIndex.search(officialQuery)).receive()) {
|
||||||
|
var officialHits = officialResults.totalHitsCount();
|
||||||
|
var officialKeys = getResults(officialResults).stream().toList();
|
||||||
|
if (officialHits.exact()) {
|
||||||
|
Assertions.assertEquals(officialKeys.size(), officialHits.value());
|
||||||
|
} else {
|
||||||
|
Assertions.assertTrue(officialKeys.size() >= officialHits.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hits.exact() && officialHits.exact()) {
|
||||||
|
assertExactHits(officialHits.value(), hits);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assertions.assertEquals(officialKeys.size(), keys.size());
|
||||||
|
|
||||||
|
assertResults(officialKeys, keys, expectedQueryType.sorted(), expectedQueryType.sortedByScore());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("provideQueryArgumentsScoreModeAndSort")
|
@MethodSource("provideQueryArgumentsScoreModeAndSort")
|
||||||
public void testSearchNoDocs(boolean shards, MultiSort<SearchResultKey<String>> multiSort) throws Throwable {
|
public void testSearchNoDocs(boolean shards, MultiSort<SearchResultKey<String>> multiSort) throws Throwable {
|
||||||
var sorted = multiSort.isSorted();
|
|
||||||
var sortedByScore = multiSort.getQuerySort().getBasicType$() == BasicType.ScoreSort;
|
|
||||||
runSearchers(new ExpectedQueryType(shards, sorted, sortedByScore, true, false), searcher -> {
|
|
||||||
var luceneIndex = getLuceneIndex(shards, searcher);
|
|
||||||
ClientQueryParamsBuilder<SearchResultKey<String>> queryBuilder = ClientQueryParams.builder();
|
ClientQueryParamsBuilder<SearchResultKey<String>> queryBuilder = ClientQueryParams.builder();
|
||||||
queryBuilder.query(new MatchNoDocsQuery());
|
queryBuilder.query(new MatchNoDocsQuery());
|
||||||
queryBuilder.snapshot(null);
|
queryBuilder.snapshot(null);
|
||||||
queryBuilder.complete(true);
|
queryBuilder.complete(true);
|
||||||
queryBuilder.sort(multiSort);
|
queryBuilder.sort(multiSort);
|
||||||
var query = queryBuilder.build();
|
|
||||||
try (var results = run(luceneIndex.search(query)).receive()) {
|
|
||||||
var hits = results.totalHitsCount();
|
|
||||||
assertExactHits(searcher, query, 0, hits);
|
|
||||||
|
|
||||||
var keys = getResults(results);
|
ExpectedQueryType expectedQueryType = new ExpectedQueryType(shards, multiSort, true, false);
|
||||||
assertEquals(List.of(), keys);
|
testSearch(queryBuilder, expectedQueryType);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("provideQueryArgumentsScoreModeAndSort")
|
@MethodSource("provideQueryArgumentsScoreModeAndSort")
|
||||||
public void testSearchAllDocs(boolean shards, MultiSort<SearchResultKey<String>> multiSort) throws Throwable {
|
public void testSearchAllDocs(boolean shards, MultiSort<SearchResultKey<String>> multiSort) throws Throwable {
|
||||||
var sorted = multiSort.isSorted();
|
|
||||||
var sortedByScore = multiSort.getQuerySort().getBasicType$() == BasicType.ScoreSort;
|
|
||||||
runSearchers(new ExpectedQueryType(shards, sorted, sortedByScore, true, false), (LocalSearcher searcher) -> {
|
|
||||||
var luceneIndex = getLuceneIndex(shards, searcher);
|
|
||||||
ClientQueryParamsBuilder<SearchResultKey<String>> queryBuilder = ClientQueryParams.builder();
|
ClientQueryParamsBuilder<SearchResultKey<String>> queryBuilder = ClientQueryParams.builder();
|
||||||
queryBuilder.query(new MatchAllDocsQuery());
|
queryBuilder.query(new MatchAllDocsQuery());
|
||||||
queryBuilder.snapshot(null);
|
queryBuilder.snapshot(null);
|
||||||
queryBuilder.complete(true);
|
queryBuilder.complete(true);
|
||||||
queryBuilder.sort(multiSort);
|
queryBuilder.sort(multiSort);
|
||||||
var query = queryBuilder.build();
|
|
||||||
try (var results = run(luceneIndex.search(query)).receive()) {
|
|
||||||
var hits = results.totalHitsCount();
|
|
||||||
assertHitsIfPossible(ELEMENTS.size(), hits);
|
|
||||||
|
|
||||||
var keys = getResults(results);
|
ExpectedQueryType expectedQueryType = new ExpectedQueryType(shards, multiSort, true, false);
|
||||||
|
testSearch(queryBuilder, expectedQueryType);
|
||||||
var officialSearcher = new OfficialSearcher();
|
|
||||||
luceneIndex = getLuceneIndex(shards, officialSearcher);
|
|
||||||
var officialQuery = queryBuilder.limit(ELEMENTS.size() * 2L).build();
|
|
||||||
try (var officialResults = run(luceneIndex.search(officialQuery)).receive()) {
|
|
||||||
var officialKeys = getResults(officialResults).stream().toList();
|
|
||||||
|
|
||||||
assertResults(officialKeys, keys, sorted, sortedByScore);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertResults(List<Scored> expectedKeys, List<Scored> resultKeys, boolean sorted, boolean sortedByScore) {
|
private void assertResults(List<Scored> expectedKeys, List<Scored> resultKeys, boolean sorted, boolean sortedByScore) {
|
||||||
@ -335,14 +345,9 @@ public class TestLuceneSearches {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertExactHits(LocalSearcher searcher,
|
private void assertExactHits(long expectedCount, TotalHitsCount hits) {
|
||||||
ClientQueryParams<SearchResultKey<String>> query,
|
|
||||||
long expectedCount,
|
|
||||||
TotalHitsCount hits) {
|
|
||||||
if (supportsPreciseHitsCount(searcher, query)) {
|
|
||||||
assertEquals(new TotalHitsCount(expectedCount, true), hits);
|
assertEquals(new TotalHitsCount(expectedCount, true), hits);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private List<Scored> getResults(SearchResultKeys<String> results) {
|
private List<Scored> getResults(SearchResultKeys<String> results) {
|
||||||
return run(results
|
return run(results
|
||||||
|
Loading…
Reference in New Issue
Block a user