CavalliumDBEngine/src/main/java/it/cavallium/dbengine/client/SearchResultKeys.java

26 lines
671 B
Java
Raw Normal View History

2021-02-03 20:13:17 +01:00
package it.cavallium.dbengine.client;
import it.cavallium.dbengine.database.collections.Joiner.ValueGetter;
import lombok.Value;
2021-02-03 20:13:17 +01:00
import reactor.core.publisher.Flux;
@Value
2021-02-03 20:13:17 +01:00
public class SearchResultKeys<T> {
Flux<SearchResultKey<T>> results;
long totalHitsCount;
2021-02-03 20:13:17 +01:00
public static <T, U> SearchResultKeys<T> empty() {
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<>(
results.flatMapSequential(item -> valuesGetter
.get(item.getKey())
.map(value -> new SearchResultItem<>(item.getKey(), value, item.getScore()))),
totalHitsCount
);
}
2021-02-03 20:13:17 +01:00
}