2021-02-03 20:13:17 +01:00
|
|
|
package it.cavallium.dbengine.client;
|
|
|
|
|
2021-09-19 19:59:37 +02:00
|
|
|
import io.net5.buffer.api.Drop;
|
|
|
|
import io.net5.buffer.api.Owned;
|
|
|
|
import io.net5.buffer.api.internal.ResourceSupport;
|
2021-08-04 01:12:39 +02:00
|
|
|
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
|
2021-08-24 11:53:19 +02:00
|
|
|
import it.cavallium.dbengine.database.LLSearchResultShard;
|
2021-07-17 11:52:08 +02:00
|
|
|
import it.cavallium.dbengine.database.collections.ValueGetter;
|
2021-08-24 11:53:19 +02:00
|
|
|
import java.util.Objects;
|
2021-07-10 20:52:01 +02:00
|
|
|
import org.reactivestreams.Publisher;
|
2021-08-24 11:53:19 +02:00
|
|
|
import org.warp.commonutils.log.Logger;
|
|
|
|
import org.warp.commonutils.log.LoggerFactory;
|
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-09-19 19:59:37 +02:00
|
|
|
public final class SearchResultKeys<T> extends ResourceSupport<SearchResultKeys<T>, SearchResultKeys<T>> {
|
2021-08-24 11:53:19 +02:00
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SearchResultKeys.class);
|
|
|
|
|
2021-09-19 19:59:37 +02:00
|
|
|
private Flux<SearchResultKey<T>> results;
|
|
|
|
private TotalHitsCount totalHitsCount;
|
2021-08-24 11:53:19 +02:00
|
|
|
|
2021-09-19 19:59:37 +02:00
|
|
|
public SearchResultKeys(Flux<SearchResultKey<T>> results, TotalHitsCount totalHitsCount,
|
|
|
|
Drop<SearchResultKeys<T>> drop) {
|
2021-09-23 15:34:56 +02:00
|
|
|
super(drop);
|
2021-08-24 11:53:19 +02:00
|
|
|
this.results = results;
|
|
|
|
this.totalHitsCount = totalHitsCount;
|
|
|
|
}
|
2021-02-03 20:13:17 +01:00
|
|
|
|
2021-08-24 14:13:43 +02:00
|
|
|
public static <T> SearchResultKeys<T> empty() {
|
2021-09-19 19:59:37 +02:00
|
|
|
return new SearchResultKeys<T>(Flux.empty(), TotalHitsCount.of(0, true), d -> {});
|
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-09-19 19:59:37 +02:00
|
|
|
)), totalHitsCount, d -> this.close());
|
2021-08-24 11:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Flux<SearchResultKey<T>> results() {
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TotalHitsCount totalHitsCount() {
|
|
|
|
return totalHitsCount;
|
|
|
|
}
|
|
|
|
|
2021-09-19 19:59:37 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "SearchResultKeys[" + "results=" + results + ", " + "totalHitsCount=" + totalHitsCount + ']';
|
2021-08-24 11:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-09-19 19:59:37 +02:00
|
|
|
protected RuntimeException createResourceClosedException() {
|
|
|
|
return new IllegalStateException("Closed");
|
2021-08-24 11:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-09-19 19:59:37 +02:00
|
|
|
protected Owned<SearchResultKeys<T>> prepareSend() {
|
|
|
|
var results = this.results;
|
|
|
|
var totalHitsCount = this.totalHitsCount;
|
|
|
|
makeInaccessible();
|
|
|
|
return drop -> new SearchResultKeys<>(results, totalHitsCount, drop);
|
2021-03-05 16:17:37 +01:00
|
|
|
}
|
2021-08-24 11:53:19 +02:00
|
|
|
|
2021-09-23 15:34:56 +02:00
|
|
|
protected void makeInaccessible() {
|
2021-09-19 19:59:37 +02:00
|
|
|
this.results = null;
|
|
|
|
this.totalHitsCount = null;
|
2021-08-24 11:53:19 +02:00
|
|
|
}
|
|
|
|
|
2021-02-03 20:13:17 +01:00
|
|
|
}
|