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.client.query.QueryParser;
|
|
|
|
import it.cavallium.dbengine.client.query.current.data.QueryParams;
|
|
|
|
import it.cavallium.dbengine.lucene.LuceneUtils;
|
|
|
|
import java.util.Objects;
|
|
|
|
import org.apache.lucene.search.Query;
|
|
|
|
import org.apache.lucene.search.ScoreMode;
|
|
|
|
import org.apache.lucene.search.Sort;
|
|
|
|
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-06 01:30:37 +02:00
|
|
|
if (queryParams.scoreMode().needsScores()) {
|
2021-07-06 00:30:14 +02:00
|
|
|
throw new UnsupportedOperationException("Can't use the unscored searcher to do a scored query");
|
|
|
|
}
|
2021-07-06 01:30:37 +02:00
|
|
|
if (queryParams.sort() != null && queryParams.sort() != Sort.RELEVANCE) {
|
2021-07-06 00:30:14 +02:00
|
|
|
throw new UnsupportedOperationException("Can't use the unscored searcher to do a sorted query");
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
UnsortedCollectorManager unsortedCollectorManager = new UnsortedCollectorManager(() -> TopDocsSearcher.getTopDocsCollector(null,
|
|
|
|
LuceneUtils.safeLongToInt(paginationInfo.firstPageOffset() + paginationInfo.firstPageLimit()),
|
|
|
|
null,
|
|
|
|
1000
|
|
|
|
), queryParams.offset(), queryParams.limit());
|
2021-07-06 01:30:37 +02:00
|
|
|
return new UnscoredLuceneShardSearcher(unsortedCollectorManager, queryParams.query(), paginationInfo);
|
2021-07-06 00:30:14 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|