package it.cavallium.dbengine.client; import it.cavallium.dbengine.client.query.ClientQueryParams; import it.cavallium.dbengine.client.query.current.data.Query; import it.cavallium.dbengine.database.Delta; import it.cavallium.dbengine.database.LLSnapshottable; import it.cavallium.dbengine.database.collections.ValueGetter; import it.cavallium.dbengine.database.collections.ValueTransformer; import java.util.Map.Entry; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.util.function.Tuple2; import reactor.util.function.Tuple3; import reactor.util.function.Tuples; @SuppressWarnings("unused") public interface LuceneIndex extends LLSnapshottable { Mono addDocument(T key, U value); Mono addDocuments(Flux> entries); Mono deleteDocument(T key); Mono updateDocument(T key, @NotNull U value); Mono updateDocuments(Flux> entries); default Mono updateOrDeleteDocument(T key, @Nullable U value) { if (value == null) { return deleteDocument(key); } else { return updateDocument(key, value); } } default Mono updateOrDeleteDocumentIfModified(T key, @NotNull Delta delta) { return updateOrDeleteDocumentIfModified(key, delta.current(), delta.isModified()); } default Mono updateOrDeleteDocumentIfModified(T key, @Nullable U currentValue, boolean modified) { if (modified) { return updateOrDeleteDocument(key, currentValue); } else { return Mono.empty(); } } Mono deleteAll(); Mono> moreLikeThis(ClientQueryParams> queryParams, T key, U mltDocumentValue); default Mono> moreLikeThisWithValues(ClientQueryParams> queryParams, T key, U mltDocumentValue, ValueGetter valueGetter) { return this.moreLikeThisWithTransformer(queryParams, key, mltDocumentValue, getValueGetterTransformer(valueGetter)); } Mono> moreLikeThisWithTransformer(ClientQueryParams> queryParams, T key, U mltDocumentValue, ValueTransformer valueTransformer); Mono> search(ClientQueryParams> queryParams); default Mono> searchWithValues(ClientQueryParams> queryParams, ValueGetter valueGetter) { return this.searchWithTransformer(queryParams, getValueGetterTransformer(valueGetter) ); } Mono> searchWithTransformer(ClientQueryParams> queryParams, ValueTransformer valueTransformer); Mono count(@Nullable CompositeSnapshot snapshot, Query query); boolean isLowMemoryMode(); Mono close(); Mono flush(); Mono refresh(boolean force); private static ValueTransformer getValueGetterTransformer(ValueGetter valueGetter) { return new ValueTransformer() { @Override public Flux> transform(Flux> keys) { return keys.flatMapSequential(key -> valueGetter .get(key.getT2()) .map(result -> Tuples.of(key.getT1(), key.getT2(), result))); } }; } }