2021-02-03 20:13:17 +01:00
|
|
|
package it.cavallium.dbengine.client;
|
|
|
|
|
2021-08-04 01:12:39 +02:00
|
|
|
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
|
2021-07-17 11:52:08 +02:00
|
|
|
import it.cavallium.dbengine.database.collections.ValueGetter;
|
2021-07-10 20:52:01 +02:00
|
|
|
import org.reactivestreams.Publisher;
|
2021-02-03 20:13:17 +01:00
|
|
|
import reactor.core.publisher.Flux;
|
2021-07-10 20:52:01 +02:00
|
|
|
import reactor.core.publisher.Mono;
|
2021-02-03 20:13:17 +01:00
|
|
|
|
2021-04-03 19:09:06 +02:00
|
|
|
@SuppressWarnings("unused")
|
2021-08-04 01:12:39 +02:00
|
|
|
public record SearchResultKeys<T>(Flux<SearchResultKey<T>> results, TotalHitsCount totalHitsCount, Mono<Void> release) {
|
2021-02-03 20:13:17 +01:00
|
|
|
|
|
|
|
public static <T, U> SearchResultKeys<T> empty() {
|
2021-08-04 01:12:39 +02:00
|
|
|
return new SearchResultKeys<>(Flux.empty(), TotalHitsCount.of(0, true), Mono.empty());
|
2021-02-03 20:13:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public <U> SearchResult<T, U> withValues(ValueGetter<T, U> valuesGetter) {
|
2021-07-05 12:05:45 +02:00
|
|
|
return new SearchResult<>(results.map(item -> new SearchResultItem<>(item.key(),
|
|
|
|
item.key().flatMap(valuesGetter::get),
|
|
|
|
item.score()
|
2021-07-10 20:52:01 +02:00
|
|
|
)), totalHitsCount, release);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Flux<SearchResultKey<T>> resultsThenRelease() {
|
|
|
|
return Flux
|
|
|
|
.usingWhen(
|
|
|
|
Mono.just(true),
|
|
|
|
_unused -> results,
|
|
|
|
_unused -> release
|
|
|
|
);
|
2021-03-05 16:17:37 +01:00
|
|
|
}
|
2021-02-03 20:13:17 +01:00
|
|
|
}
|