Sort shards during merge
This commit is contained in:
parent
6c97b0f068
commit
7cebcd7e92
|
@ -62,6 +62,26 @@ class FieldSimpleLuceneShardSearcher implements LuceneShardSearcher {
|
||||||
public Mono<LuceneSearchResult> collect(LocalQueryParams queryParams, String keyFieldName, Scheduler scheduler) {
|
public Mono<LuceneSearchResult> collect(LocalQueryParams queryParams, String keyFieldName, Scheduler scheduler) {
|
||||||
return Mono
|
return Mono
|
||||||
.fromCallable(() -> {
|
.fromCallable(() -> {
|
||||||
|
TopDocs result;
|
||||||
|
if (queryParams.sort() != null) {
|
||||||
|
TopFieldDocs[] topDocs;
|
||||||
|
synchronized (lock) {
|
||||||
|
topDocs = new TopFieldDocs[collectors.size()];
|
||||||
|
var i = 0;
|
||||||
|
for (TopFieldCollector collector : collectors) {
|
||||||
|
topDocs[i] = collector.topDocs();
|
||||||
|
for (ScoreDoc scoreDoc : topDocs[i].scoreDocs) {
|
||||||
|
scoreDoc.shardIndex = i;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = TopDocs.merge(queryParams.sort(), LuceneUtils.safeLongToInt(paginationInfo.firstPageOffset()),
|
||||||
|
LuceneUtils.safeLongToInt(paginationInfo.firstPageLimit()),
|
||||||
|
topDocs,
|
||||||
|
TIE_BREAKER
|
||||||
|
);
|
||||||
|
} else {
|
||||||
TopDocs[] topDocs;
|
TopDocs[] topDocs;
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
topDocs = new TopDocs[collectors.size()];
|
topDocs = new TopDocs[collectors.size()];
|
||||||
|
@ -74,11 +94,12 @@ class FieldSimpleLuceneShardSearcher implements LuceneShardSearcher {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var result = TopDocs.merge(LuceneUtils.safeLongToInt(paginationInfo.firstPageOffset()),
|
result = TopDocs.merge(LuceneUtils.safeLongToInt(paginationInfo.firstPageOffset()),
|
||||||
LuceneUtils.safeLongToInt(paginationInfo.firstPageLimit()),
|
LuceneUtils.safeLongToInt(paginationInfo.firstPageLimit()),
|
||||||
topDocs,
|
topDocs,
|
||||||
TIE_BREAKER
|
TIE_BREAKER
|
||||||
);
|
);
|
||||||
|
}
|
||||||
IndexSearchers indexSearchers;
|
IndexSearchers indexSearchers;
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
indexSearchers = IndexSearchers.of(indexSearchersArray);
|
indexSearchers = IndexSearchers.of(indexSearchersArray);
|
||||||
|
@ -87,7 +108,7 @@ class FieldSimpleLuceneShardSearcher implements LuceneShardSearcher {
|
||||||
.convertHits(result.scoreDocs, indexSearchers, keyFieldName, scheduler);
|
.convertHits(result.scoreDocs, indexSearchers, keyFieldName, scheduler);
|
||||||
|
|
||||||
Flux<LLKeyScore> nextHits = Flux.defer(() -> {
|
Flux<LLKeyScore> nextHits = Flux.defer(() -> {
|
||||||
if (paginationInfo.totalLimit() - paginationInfo.firstPageLimit() <= 0) {
|
if (paginationInfo.forceSinglePage() || paginationInfo.totalLimit() - paginationInfo.firstPageLimit() <= 0) {
|
||||||
return Flux.empty();
|
return Flux.empty();
|
||||||
}
|
}
|
||||||
return Flux
|
return Flux
|
||||||
|
@ -120,10 +141,19 @@ class FieldSimpleLuceneShardSearcher implements LuceneShardSearcher {
|
||||||
)
|
)
|
||||||
.collect(Collectors.toCollection(ObjectArrayList::new))
|
.collect(Collectors.toCollection(ObjectArrayList::new))
|
||||||
.map(topFieldDocs -> topFieldDocs.toArray(TopFieldDocs[]::new))
|
.map(topFieldDocs -> topFieldDocs.toArray(TopFieldDocs[]::new))
|
||||||
.map(topFieldDocs -> TopDocs.merge(0, s.currentPageLimit(),
|
.map(topFieldDocs -> {
|
||||||
|
if (queryParams.sort() != null) {
|
||||||
|
return TopDocs.merge(queryParams.sort(), 0, s.currentPageLimit(),
|
||||||
topFieldDocs,
|
topFieldDocs,
|
||||||
TIE_BREAKER
|
TIE_BREAKER
|
||||||
))
|
);
|
||||||
|
} else {
|
||||||
|
return TopDocs.merge(0, s.currentPageLimit(),
|
||||||
|
topFieldDocs,
|
||||||
|
TIE_BREAKER
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
.blockOptional().orElseThrow();
|
.blockOptional().orElseThrow();
|
||||||
var pageLastDoc = LuceneUtils.getLastFieldDoc(pageTopDocs.scoreDocs);
|
var pageLastDoc = LuceneUtils.getLastFieldDoc(pageTopDocs.scoreDocs);
|
||||||
sink.next(pageTopDocs);
|
sink.next(pageTopDocs);
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class SharedSortedLuceneMultiSearcher implements LuceneMultiSearcher {
|
||||||
if (queryParams.limit() <= MAX_SINGLE_SEARCH_LIMIT) {
|
if (queryParams.limit() <= MAX_SINGLE_SEARCH_LIMIT) {
|
||||||
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), queryParams.limit(), true);
|
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), queryParams.limit(), true);
|
||||||
} else {
|
} else {
|
||||||
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), FIRST_PAGE_LIMIT, true);
|
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), FIRST_PAGE_LIMIT, false);
|
||||||
}
|
}
|
||||||
CollectorManager<TopFieldCollector, TopFieldDocs> sharedManager = TopFieldCollector
|
CollectorManager<TopFieldCollector, TopFieldDocs> sharedManager = TopFieldCollector
|
||||||
.createSharedManager(luceneSort, LuceneUtils.safeLongToInt(paginationInfo.firstPageOffset() + paginationInfo.firstPageLimit()), null, 1000);
|
.createSharedManager(luceneSort, LuceneUtils.safeLongToInt(paginationInfo.firstPageOffset() + paginationInfo.firstPageLimit()), null, 1000);
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class SimpleLuceneLocalSearcher implements LuceneLocalSearcher {
|
||||||
if (queryParams.limit() <= MAX_SINGLE_SEARCH_LIMIT) {
|
if (queryParams.limit() <= MAX_SINGLE_SEARCH_LIMIT) {
|
||||||
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), queryParams.limit(), true);
|
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), queryParams.limit(), true);
|
||||||
} else {
|
} else {
|
||||||
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), FIRST_PAGE_LIMIT, true);
|
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), FIRST_PAGE_LIMIT, false);
|
||||||
}
|
}
|
||||||
//noinspection BlockingMethodInNonBlockingContext
|
//noinspection BlockingMethodInNonBlockingContext
|
||||||
TopDocs firstPageTopDocs = TopDocsSearcher.getTopDocs(indexSearcher,
|
TopDocs firstPageTopDocs = TopDocsSearcher.getTopDocs(indexSearcher,
|
||||||
|
@ -64,7 +64,7 @@ public class SimpleLuceneLocalSearcher implements LuceneLocalSearcher {
|
||||||
|
|
||||||
|
|
||||||
Flux<LLKeyScore> nextHits = Flux.defer(() -> {
|
Flux<LLKeyScore> nextHits = Flux.defer(() -> {
|
||||||
if (paginationInfo.totalLimit() - paginationInfo.firstPageLimit() <= 0) {
|
if (paginationInfo.forceSinglePage() || paginationInfo.totalLimit() - paginationInfo.firstPageLimit() <= 0) {
|
||||||
return Flux.empty();
|
return Flux.empty();
|
||||||
}
|
}
|
||||||
return Flux
|
return Flux
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class UnscoredLuceneMultiSearcher implements LuceneMultiSearcher {
|
||||||
if (queryParams.limit() <= MAX_SINGLE_SEARCH_LIMIT) {
|
if (queryParams.limit() <= MAX_SINGLE_SEARCH_LIMIT) {
|
||||||
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), queryParams.limit(), true);
|
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), queryParams.limit(), true);
|
||||||
} else {
|
} else {
|
||||||
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), FIRST_PAGE_LIMIT, true);
|
paginationInfo = new PaginationInfo(queryParams.limit(), queryParams.offset(), FIRST_PAGE_LIMIT, false);
|
||||||
}
|
}
|
||||||
UnsortedCollectorManager unsortedCollectorManager = new UnsortedCollectorManager(() -> TopDocsSearcher.getTopDocsCollector(null,
|
UnsortedCollectorManager unsortedCollectorManager = new UnsortedCollectorManager(() -> TopDocsSearcher.getTopDocsCollector(null,
|
||||||
LuceneUtils.safeLongToInt(paginationInfo.firstPageOffset() + paginationInfo.firstPageLimit()),
|
LuceneUtils.safeLongToInt(paginationInfo.firstPageOffset() + paginationInfo.firstPageLimit()),
|
||||||
|
|
|
@ -84,7 +84,7 @@ class UnscoredLuceneShardSearcher implements LuceneShardSearcher {
|
||||||
.convertHits(result.scoreDocs, indexSearchers, keyFieldName, scheduler);
|
.convertHits(result.scoreDocs, indexSearchers, keyFieldName, scheduler);
|
||||||
|
|
||||||
Flux<LLKeyScore> nextHits = Flux.defer(() -> {
|
Flux<LLKeyScore> nextHits = Flux.defer(() -> {
|
||||||
if (paginationInfo.totalLimit() - paginationInfo.firstPageLimit() <= 0) {
|
if (paginationInfo.forceSinglePage() || paginationInfo.totalLimit() - paginationInfo.firstPageLimit() <= 0) {
|
||||||
return Flux.empty();
|
return Flux.empty();
|
||||||
}
|
}
|
||||||
return Flux
|
return Flux
|
||||||
|
|
Loading…
Reference in New Issue
Block a user