2021-07-06 00:30:14 +02:00
|
|
|
package it.cavallium.dbengine.lucene.searcher;
|
|
|
|
|
|
|
|
import static it.cavallium.dbengine.lucene.searcher.PaginationInfo.FIRST_PAGE_LIMIT;
|
|
|
|
import static it.cavallium.dbengine.lucene.searcher.PaginationInfo.MAX_SINGLE_SEARCH_LIMIT;
|
|
|
|
|
|
|
|
import it.cavallium.dbengine.lucene.LuceneUtils;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
public class UnscoredLuceneMultiSearcher implements LuceneMultiSearcher {
|
|
|
|
|
|
|
|
@Override
|
2021-07-06 01:30:37 +02:00
|
|
|
public Mono<LuceneShardSearcher> createShardSearcher(LocalQueryParams queryParams) {
|
2021-07-06 00:30:14 +02:00
|
|
|
return Mono
|
|
|
|
.fromCallable(() -> {
|
2021-07-08 17:01:56 +02:00
|
|
|
if (queryParams.isScored()) {
|
|
|
|
throw new UnsupportedOperationException("Can't use the unscored searcher to do a scored or sorted query");
|
2021-07-06 00:30:14 +02:00
|
|
|
}
|
|
|
|
PaginationInfo paginationInfo;
|
|
|
|
if (queryParams.limit() <= MAX_SINGLE_SEARCH_LIMIT) {
|
|
|
|
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), queryParams.limit(), true);
|
|
|
|
} else {
|
2021-07-06 01:52:12 +02:00
|
|
|
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), FIRST_PAGE_LIMIT, false);
|
2021-07-06 00:30:14 +02:00
|
|
|
}
|
2021-07-08 17:01:56 +02:00
|
|
|
UnscoredCollectorManager unsortedCollectorManager = new UnscoredCollectorManager(() -> TopDocsSearcher.getTopDocsCollector(queryParams.sort(),
|
2021-07-06 00:30:14 +02:00
|
|
|
LuceneUtils.safeLongToInt(paginationInfo.firstPageOffset() + paginationInfo.firstPageLimit()),
|
|
|
|
null,
|
|
|
|
1000
|
2021-07-08 17:01:56 +02:00
|
|
|
), queryParams.offset(), queryParams.limit(), queryParams.sort());
|
2021-07-06 01:30:37 +02:00
|
|
|
return new UnscoredLuceneShardSearcher(unsortedCollectorManager, queryParams.query(), paginationInfo);
|
2021-07-06 00:30:14 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|