2021-02-03 20:13:17 +01:00
|
|
|
package it.cavallium.dbengine.client;
|
|
|
|
|
|
|
|
import it.cavallium.dbengine.database.collections.Joiner.ValueGetter;
|
2021-03-27 03:35:27 +01:00
|
|
|
import lombok.Value;
|
2021-02-03 20:13:17 +01:00
|
|
|
import reactor.core.publisher.Flux;
|
|
|
|
|
2021-03-27 03:35:27 +01:00
|
|
|
@Value
|
2021-02-03 20:13:17 +01:00
|
|
|
public class SearchResultKeys<T> {
|
|
|
|
|
2021-03-27 03:35:27 +01:00
|
|
|
Flux<SearchResultKey<T>> results;
|
|
|
|
long totalHitsCount;
|
2021-02-03 20:13:17 +01:00
|
|
|
|
|
|
|
public static <T, U> SearchResultKeys<T> empty() {
|
2021-03-27 03:35:27 +01:00
|
|
|
return new SearchResultKeys<>(Flux.empty(), 0L);
|
2021-02-03 20:13:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public <U> SearchResult<T, U> withValues(ValueGetter<T, U> valuesGetter) {
|
2021-03-03 15:03:25 +01:00
|
|
|
return new SearchResult<>(
|
2021-03-27 03:35:27 +01:00
|
|
|
results.flatMapSequential(item -> valuesGetter
|
|
|
|
.get(item.getKey())
|
|
|
|
.map(value -> new SearchResultItem<>(item.getKey(), value, item.getScore()))),
|
|
|
|
totalHitsCount
|
2021-03-05 16:17:37 +01:00
|
|
|
);
|
|
|
|
}
|
2021-02-03 20:13:17 +01:00
|
|
|
}
|