Update database

This commit is contained in:
Andrea Cavalli 2021-11-08 11:17:52 +01:00
parent 63cd178988
commit 59aa1ef5c6
21 changed files with 109 additions and 91 deletions

View File

@ -26,7 +26,7 @@ public class SwappableLuceneSearcher implements LocalSearcher, MultiSearcher, Cl
} }
@Override @Override
public Mono<Send<LuceneSearchResult>> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono, public Mono<LuceneSearchResult> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -51,7 +51,7 @@ public class SwappableLuceneSearcher implements LocalSearcher, MultiSearcher, Cl
} }
@Override @Override
public Mono<Send<LuceneSearchResult>> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, public Mono<LuceneSearchResult> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {

View File

@ -62,37 +62,39 @@ public final class Hits<T> extends ResourceSupport<Hits<T>, Hits<T>> {
return new Hits<>(hitsEntry, hits.totalHitsCount, hits::close); return new Hits<>(hitsEntry, hits.totalHitsCount, hits::close);
} }
public static <T, U> Function<Send<Hits<HitKey<T>>>, Send<Hits<LazyHitEntry<T, U>>>> generateMapper( public static <T, U> Function<Hits<HitKey<T>>, Hits<LazyHitEntry<T, U>>> generateMapper(
ValueGetter<T, U> valueGetter) { ValueGetter<T, U> valueGetter) {
return resultToReceive -> { return result -> {
var result = resultToReceive.receive();
var hitsToTransform = result.results() var hitsToTransform = result.results()
.map(hit -> new LazyHitEntry<>(Mono.just(hit.key()), valueGetter.get(hit.key()), hit.score())); .map(hit -> new LazyHitEntry<>(Mono.just(hit.key()), valueGetter.get(hit.key()), hit.score()));
return new Hits<>(hitsToTransform, result.totalHitsCount(), result::close).send(); return new Hits<>(hitsToTransform, result.totalHitsCount(), result::close);
}; };
} }
public static <T, U> Function<Send<Hits<HitKey<T>>>, Send<Hits<LazyHitEntry<T, U>>>> generateMapper( public static <T, U> Function<Hits<HitKey<T>>, Hits<LazyHitEntry<T, U>>> generateMapper(
ValueTransformer<T, U> valueTransformer) { ValueTransformer<T, U> valueTransformer) {
return resultToReceive -> { return result -> {
var result = resultToReceive.receive(); try {
var sharedHitsFlux = result.results().publish().refCount(3);
var scoresFlux = sharedHitsFlux.map(HitKey::score);
var keysFlux = sharedHitsFlux.map(HitKey::key);
var sharedHitsFlux = result.results().publish().refCount(3); var valuesFlux = valueTransformer.transform(keysFlux);
var scoresFlux = sharedHitsFlux.map(HitKey::score);
var keysFlux = sharedHitsFlux.map(HitKey::key);
var valuesFlux = valueTransformer.transform(keysFlux); var transformedFlux = Flux.zip((Object[] data) -> {
//noinspection unchecked
var keyMono = Mono.just((T) data[0]);
//noinspection unchecked
var valMono = Mono.just((U) data[1]);
var score = (Float) data[2];
return new LazyHitEntry<>(keyMono, valMono, score);
}, keysFlux, valuesFlux, scoresFlux);
var transformedFlux = Flux.zip((Object[] data) -> { return new Hits<>(transformedFlux, result.totalHitsCount(), result::close);
//noinspection unchecked } catch (Throwable t) {
var keyMono = Mono.just((T) data[0]); result.close();
//noinspection unchecked throw t;
var valMono = Mono.just((U) data[1]); }
var score = (Float) data[2];
return new LazyHitEntry<>(keyMono, valMono, score);
}, keysFlux, valuesFlux, scoresFlux);
return new Hits<>(transformedFlux, result.totalHitsCount(), result::close).send();
}; };
} }

View File

@ -48,10 +48,10 @@ public interface LuceneIndex<T, U> extends LLSnapshottable {
Mono<Void> deleteAll(); Mono<Void> deleteAll();
Mono<Send<Hits<HitKey<T>>>> moreLikeThis(ClientQueryParams queryParams, T key, Mono<Hits<HitKey<T>>> moreLikeThis(ClientQueryParams queryParams, T key,
U mltDocumentValue); U mltDocumentValue);
Mono<Send<Hits<HitKey<T>>>> search(ClientQueryParams queryParams); Mono<Hits<HitKey<T>>> search(ClientQueryParams queryParams);
Mono<TotalHitsCount> count(@Nullable CompositeSnapshot snapshot, Query query); Mono<TotalHitsCount> count(@Nullable CompositeSnapshot snapshot, Query query);

View File

@ -82,7 +82,7 @@ public class LuceneIndexImpl<T, U> implements LuceneIndex<T, U> {
} }
@Override @Override
public Mono<Send<Hits<HitKey<T>>>> moreLikeThis(ClientQueryParams queryParams, public Mono<Hits<HitKey<T>>> moreLikeThis(ClientQueryParams queryParams,
T key, T key,
U mltDocumentValue) { U mltDocumentValue) {
Flux<Tuple2<String, Set<String>>> mltDocumentFields Flux<Tuple2<String, Set<String>>> mltDocumentFields
@ -99,7 +99,7 @@ public class LuceneIndexImpl<T, U> implements LuceneIndex<T, U> {
} }
@Override @Override
public Mono<Send<Hits<HitKey<T>>>> search(ClientQueryParams queryParams) { public Mono<Hits<HitKey<T>>> search(ClientQueryParams queryParams) {
return luceneIndex return luceneIndex
.search(resolveSnapshot(queryParams.snapshot()), .search(resolveSnapshot(queryParams.snapshot()),
queryParams.toQueryParams(), queryParams.toQueryParams(),
@ -109,13 +109,12 @@ public class LuceneIndexImpl<T, U> implements LuceneIndex<T, U> {
.single(); .single();
} }
private Send<Hits<HitKey<T>>> mapResults(Send<LLSearchResultShard> llSearchResultToReceive) { private Hits<HitKey<T>> mapResults(LLSearchResultShard llSearchResult) {
var llSearchResult = llSearchResultToReceive.receive();
var scoresWithKeysFlux = llSearchResult var scoresWithKeysFlux = llSearchResult
.results() .results()
.map(hit -> new HitKey<>(indicizer.getKey(hit.key()), hit.score())); .map(hit -> new HitKey<>(indicizer.getKey(hit.key()), hit.score()));
return new Hits<>(scoresWithKeysFlux, llSearchResult.totalHitsCount(), llSearchResult::close).send(); return new Hits<>(scoresWithKeysFlux, llSearchResult.totalHitsCount(), llSearchResult::close);
} }
@Override @Override
@ -123,8 +122,8 @@ public class LuceneIndexImpl<T, U> implements LuceneIndex<T, U> {
return this return this
.search(ClientQueryParams.builder().snapshot(snapshot).query(query).limit(0).build()) .search(ClientQueryParams.builder().snapshot(snapshot).query(query).limit(0).build())
.single() .single()
.map(searchResultKeysSend -> { .map(searchResultKeys -> {
try (var searchResultKeys = searchResultKeysSend.receive()) { try (searchResultKeys) {
return searchResultKeys.totalHitsCount(); return searchResultKeys.totalHitsCount();
} }
}); });

View File

@ -1,5 +1,6 @@
package it.cavallium.dbengine.database; package it.cavallium.dbengine.database;
import io.net5.buffer.api.Resource;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import it.cavallium.data.generator.nativedata.Nullablefloat; import it.cavallium.data.generator.nativedata.Nullablefloat;
import it.cavallium.dbengine.client.query.current.data.NoSort; import it.cavallium.dbengine.client.query.current.data.NoSort;
@ -42,7 +43,7 @@ public interface LLLuceneIndex extends LLSnapshottable {
* The additional query will be used with the moreLikeThis query: "mltQuery AND additionalQuery" * The additional query will be used with the moreLikeThis query: "mltQuery AND additionalQuery"
* @return the collection has one or more flux * @return the collection has one or more flux
*/ */
Mono<Send<LLSearchResultShard>> moreLikeThis(@Nullable LLSnapshot snapshot, Mono<LLSearchResultShard> moreLikeThis(@Nullable LLSnapshot snapshot,
QueryParams queryParams, QueryParams queryParams,
String keyFieldName, String keyFieldName,
Flux<Tuple2<String, Set<String>>> mltDocumentFields); Flux<Tuple2<String, Set<String>>> mltDocumentFields);
@ -52,18 +53,18 @@ public interface LLLuceneIndex extends LLSnapshottable {
* returned can be at most <code>limit * 15</code> * returned can be at most <code>limit * 15</code>
* @return the collection has one or more flux * @return the collection has one or more flux
*/ */
Mono<Send<LLSearchResultShard>> search(@Nullable LLSnapshot snapshot, QueryParams queryParams, String keyFieldName); Mono<LLSearchResultShard> search(@Nullable LLSnapshot snapshot, QueryParams queryParams, String keyFieldName);
default Mono<TotalHitsCount> count(@Nullable LLSnapshot snapshot, Query query) { default Mono<TotalHitsCount> count(@Nullable LLSnapshot snapshot, Query query) {
QueryParams params = QueryParams.of(query, 0, 0, Nullablefloat.empty(), NoSort.of(), false); QueryParams params = QueryParams.of(query, 0, 0, Nullablefloat.empty(), NoSort.of(), false);
return Mono.from(this.search(snapshot, params, null) return Mono.from(this.search(snapshot, params, null)
.map(llSearchResultShardToReceive -> { .map(llSearchResultShard -> {
try (var llSearchResultShard = llSearchResultShardToReceive.receive()) { try (llSearchResultShard) {
return llSearchResultShard.totalHitsCount(); return llSearchResultShard.totalHitsCount();
} }
}) })
.defaultIfEmpty(TotalHitsCount.of(0, true)) .defaultIfEmpty(TotalHitsCount.of(0, true))
).doOnDiscard(Send.class, Send::close); ).doOnDiscard(Send.class, Send::close).doOnDiscard(Resource.class, Resource::close);
} }
boolean isLowMemoryMode(); boolean isLowMemoryMode();

View File

@ -502,6 +502,25 @@ public class LLUtils {
.doOnDiscard(Send.class, send -> send.close()); .doOnDiscard(Send.class, send -> send.close());
} }
// todo: remove this ugly method
/**
* cleanup resource
* @param cleanupOnSuccess if true the resource will be cleaned up if the function is successful
*/
public static <U, T extends Resource<T>, V extends T> Flux<U> usingResources(Mono<V> resourceSupplier,
Function<V, Flux<U>> resourceClosure,
boolean cleanupOnSuccess) {
return Flux.usingWhen(resourceSupplier, resourceClosure, r -> {
if (cleanupOnSuccess) {
return Mono.fromRunnable(() -> r.close());
} else {
return Mono.empty();
}
}, (r, ex) -> Mono.fromRunnable(() -> r.close()), r -> Mono.fromRunnable(() -> r.close()))
.doOnDiscard(Resource.class, resource -> resource.close())
.doOnDiscard(Send.class, send -> send.close());
}
// todo: remove this ugly method // todo: remove this ugly method
/** /**
* cleanup resource * cleanup resource

View File

@ -4,6 +4,7 @@ import static it.cavallium.dbengine.database.LLUtils.MARKER_LUCENE;
import static it.cavallium.dbengine.lucene.searcher.LLSearchTransformer.NO_TRANSFORMATION; import static it.cavallium.dbengine.lucene.searcher.LLSearchTransformer.NO_TRANSFORMATION;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import io.net5.buffer.api.Resource;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import it.cavallium.dbengine.client.DirectIOOptions; import it.cavallium.dbengine.client.DirectIOOptions;
import it.cavallium.dbengine.client.IndicizerAnalyzers; import it.cavallium.dbengine.client.IndicizerAnalyzers;
@ -359,7 +360,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
} }
@Override @Override
public Mono<Send<LLSearchResultShard>> moreLikeThis(@Nullable LLSnapshot snapshot, public Mono<LLSearchResultShard> moreLikeThis(@Nullable LLSnapshot snapshot,
QueryParams queryParams, QueryParams queryParams,
String keyFieldName, String keyFieldName,
Flux<Tuple2<String, Set<String>>> mltDocumentFieldsFlux) { Flux<Tuple2<String, Set<String>>> mltDocumentFieldsFlux) {
@ -367,22 +368,23 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
var searcher = this.searcherManager.retrieveSearcher(snapshot); var searcher = this.searcherManager.retrieveSearcher(snapshot);
var transformer = new MoreLikeThisTransformer(mltDocumentFieldsFlux); var transformer = new MoreLikeThisTransformer(mltDocumentFieldsFlux);
return localSearcher.collect(searcher, localQueryParams, keyFieldName, transformer).map(resultToReceive -> { return localSearcher
var result = resultToReceive.receive(); .collect(searcher, localQueryParams, keyFieldName, transformer)
return new LLSearchResultShard(result.results(), result.totalHitsCount(), result::close).send(); .map(result -> new LLSearchResultShard(result.results(), result.totalHitsCount(), result::close))
}).doOnDiscard(Send.class, Send::close); .doOnDiscard(Send.class, Send::close)
.doOnDiscard(Resource.class, Resource::close);
} }
@Override @Override
public Mono<Send<LLSearchResultShard>> search(@Nullable LLSnapshot snapshot, QueryParams queryParams, public Mono<LLSearchResultShard> search(@Nullable LLSnapshot snapshot, QueryParams queryParams,
String keyFieldName) { String keyFieldName) {
LocalQueryParams localQueryParams = LuceneUtils.toLocalQueryParams(queryParams); LocalQueryParams localQueryParams = LuceneUtils.toLocalQueryParams(queryParams);
var searcher = searcherManager.retrieveSearcher(snapshot); var searcher = searcherManager.retrieveSearcher(snapshot);
return localSearcher.collect(searcher, localQueryParams, keyFieldName, NO_TRANSFORMATION).map(resultToReceive -> { return localSearcher
var result = resultToReceive.receive(); .collect(searcher, localQueryParams, keyFieldName, NO_TRANSFORMATION)
return new LLSearchResultShard(result.results(), result.totalHitsCount(), result::close).send(); .map(result -> new LLSearchResultShard(result.results(), result.totalHitsCount(), result::close))
}).doOnDiscard(Send.class, Send::close); .doOnDiscard(Send.class, Send::close);
} }
public Mono<Send<LLIndexSearcher>> retrieveSearcher(@Nullable LLSnapshot snapshot) { public Mono<Send<LLIndexSearcher>> retrieveSearcher(@Nullable LLSnapshot snapshot) {

View File

@ -1,6 +1,7 @@
package it.cavallium.dbengine.database.disk; package it.cavallium.dbengine.database.disk;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import io.net5.buffer.api.Resource;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import it.cavallium.dbengine.client.IndicizerAnalyzers; import it.cavallium.dbengine.client.IndicizerAnalyzers;
import it.cavallium.dbengine.client.IndicizerSimilarities; import it.cavallium.dbengine.client.IndicizerSimilarities;
@ -210,7 +211,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex {
} }
@Override @Override
public Mono<Send<LLSearchResultShard>> moreLikeThis(@Nullable LLSnapshot snapshot, public Mono<LLSearchResultShard> moreLikeThis(@Nullable LLSnapshot snapshot,
QueryParams queryParams, QueryParams queryParams,
String keyFieldName, String keyFieldName,
Flux<Tuple2<String, Set<String>>> mltDocumentFields) { Flux<Tuple2<String, Set<String>>> mltDocumentFields) {
@ -222,15 +223,13 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex {
return multiSearcher return multiSearcher
.collectMulti(searchers, localQueryParams, keyFieldName, transformer) .collectMulti(searchers, localQueryParams, keyFieldName, transformer)
// Transform the result type // Transform the result type
.map(resultToReceive -> { .map(result -> new LLSearchResultShard(result.results(), result.totalHitsCount(), result::close))
var result = resultToReceive.receive(); .doOnDiscard(Send.class, Send::close)
return new LLSearchResultShard(result.results(), result.totalHitsCount(), result::close).send(); .doOnDiscard(Resource.class, Resource::close);
})
.doOnDiscard(Send.class, Send::close);
} }
@Override @Override
public Mono<Send<LLSearchResultShard>> search(@Nullable LLSnapshot snapshot, public Mono<LLSearchResultShard> search(@Nullable LLSnapshot snapshot,
QueryParams queryParams, QueryParams queryParams,
String keyFieldName) { String keyFieldName) {
LocalQueryParams localQueryParams = LuceneUtils.toLocalQueryParams(queryParams); LocalQueryParams localQueryParams = LuceneUtils.toLocalQueryParams(queryParams);
@ -240,11 +239,8 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex {
return multiSearcher return multiSearcher
.collectMulti(searchers, localQueryParams, keyFieldName, LLSearchTransformer.NO_TRANSFORMATION) .collectMulti(searchers, localQueryParams, keyFieldName, LLSearchTransformer.NO_TRANSFORMATION)
// Transform the result type // Transform the result type
.map(resultToReceive -> { .map(result -> new LLSearchResultShard(result.results(), result.totalHitsCount(), result::close))
var result = resultToReceive.receive(); .doOnDiscard(Send.class, Send::close).doOnDiscard(Resource.class, Resource::close);
return new LLSearchResultShard(result.results(), result.totalHitsCount(), result::close).send();
})
.doOnDiscard(Send.class, Send::close);
} }
@Override @Override

View File

@ -15,7 +15,7 @@ public class AdaptiveLocalSearcher implements LocalSearcher {
private static final LocalSearcher countSearcher = new CountLocalSearcher(); private static final LocalSearcher countSearcher = new CountLocalSearcher();
@Override @Override
public Mono<Send<LuceneSearchResult>> collect(Mono<Send<LLIndexSearcher>> indexSearcher, public Mono<LuceneSearchResult> collect(Mono<Send<LLIndexSearcher>> indexSearcher,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -39,7 +39,7 @@ public class AdaptiveLocalSearcher implements LocalSearcher {
return "adaptivelocal"; return "adaptivelocal";
} }
public Mono<Send<LuceneSearchResult>> transformedCollect(Mono<Send<LLIndexSearcher>> indexSearcher, public Mono<LuceneSearchResult> transformedCollect(Mono<Send<LLIndexSearcher>> indexSearcher,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {

View File

@ -32,7 +32,7 @@ public class AdaptiveMultiSearcher implements MultiSearcher {
} }
@Override @Override
public Mono<Send<LuceneSearchResult>> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, public Mono<LuceneSearchResult> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -47,7 +47,7 @@ public class AdaptiveMultiSearcher implements MultiSearcher {
} }
} }
public Mono<Send<LuceneSearchResult>> transformedCollectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, public Mono<LuceneSearchResult> transformedCollectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {

View File

@ -13,7 +13,7 @@ import reactor.core.scheduler.Schedulers;
public class CountLocalSearcher implements LocalSearcher { public class CountLocalSearcher implements LocalSearcher {
@Override @Override
public Mono<Send<LuceneSearchResult>> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono, public Mono<LuceneSearchResult> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -38,7 +38,7 @@ public class CountLocalSearcher implements LocalSearcher {
}, },
is -> Mono.empty() is -> Mono.empty()
) )
.map(count -> new LuceneSearchResult(TotalHitsCount.of(count, true), Flux.empty(), null).send()) .map(count -> new LuceneSearchResult(TotalHitsCount.of(count, true), Flux.empty(), null))
.doOnDiscard(Send.class, Send::close); .doOnDiscard(Send.class, Send::close);
} }

View File

@ -12,7 +12,7 @@ public interface LocalSearcher {
* @param keyFieldName the name of the key field * @param keyFieldName the name of the key field
* @param transformer the search query transformer * @param transformer the search query transformer
*/ */
Mono<Send<LuceneSearchResult>> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono, Mono<LuceneSearchResult> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer); LLSearchTransformer transformer);

View File

@ -18,7 +18,7 @@ public interface MultiSearcher extends LocalSearcher {
* @param keyFieldName the name of the key field * @param keyFieldName the name of the key field
* @param transformer the search query transformer * @param transformer the search query transformer
*/ */
Mono<Send<LuceneSearchResult>> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, Mono<LuceneSearchResult> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer); LLSearchTransformer transformer);
@ -30,7 +30,7 @@ public interface MultiSearcher extends LocalSearcher {
* @param transformer the search query transformer * @param transformer the search query transformer
*/ */
@Override @Override
default Mono<Send<LuceneSearchResult>> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono, default Mono<LuceneSearchResult> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {

View File

@ -36,7 +36,7 @@ public class OfficialSearcher implements MultiSearcher {
} }
@Override @Override
public Mono<Send<LuceneSearchResult>> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, public Mono<LuceneSearchResult> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -102,7 +102,7 @@ public class OfficialSearcher implements MultiSearcher {
/** /**
* Compute the results, extracting useful data * Compute the results, extracting useful data
*/ */
private Mono<Send<LuceneSearchResult>> computeResults(Mono<TopDocs> dataMono, private Mono<LuceneSearchResult> computeResults(Mono<TopDocs> dataMono,
LLIndexSearchers indexSearchers, LLIndexSearchers indexSearchers,
String keyFieldName, String keyFieldName,
LocalQueryParams queryParams) { LocalQueryParams queryParams) {
@ -115,7 +115,7 @@ public class OfficialSearcher implements MultiSearcher {
.skip(queryParams.offsetLong()) .skip(queryParams.offsetLong())
.take(queryParams.limitLong(), true); .take(queryParams.limitLong(), true);
return new LuceneSearchResult(totalHitsCount, hitsFlux, indexSearchers::close).send(); return new LuceneSearchResult(totalHitsCount, hitsFlux, indexSearchers::close);
}); });
} }

View File

@ -32,7 +32,7 @@ import reactor.core.scheduler.Schedulers;
public class PagedLocalSearcher implements LocalSearcher { public class PagedLocalSearcher implements LocalSearcher {
@Override @Override
public Mono<Send<LuceneSearchResult>> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono, public Mono<LuceneSearchResult> collect(Mono<Send<LLIndexSearcher>> indexSearcherMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -120,7 +120,7 @@ public class PagedLocalSearcher implements LocalSearcher {
}).single(); }).single();
} }
private Mono<Send<LuceneSearchResult>> computeOtherResults(Mono<FirstPageResults> firstResultMono, private Mono<LuceneSearchResult> computeOtherResults(Mono<FirstPageResults> firstResultMono,
List<IndexSearcher> indexSearchers, List<IndexSearcher> indexSearchers,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
@ -133,7 +133,7 @@ public class PagedLocalSearcher implements LocalSearcher {
Flux<LLKeyScore> nextHitsFlux = searchOtherPages(indexSearchers, queryParams, keyFieldName, secondPageInfo); Flux<LLKeyScore> nextHitsFlux = searchOtherPages(indexSearchers, queryParams, keyFieldName, secondPageInfo);
Flux<LLKeyScore> combinedFlux = firstPageHitsFlux.concatWith(nextHitsFlux); Flux<LLKeyScore> combinedFlux = firstPageHitsFlux.concatWith(nextHitsFlux);
return new LuceneSearchResult(totalHitsCount, combinedFlux, onClose).send(); return new LuceneSearchResult(totalHitsCount, combinedFlux, onClose);
}).single(); }).single();
} }

View File

@ -32,7 +32,7 @@ public class ScoredPagedMultiSearcher implements MultiSearcher {
} }
@Override @Override
public Mono<Send<LuceneSearchResult>> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, public Mono<LuceneSearchResult> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -114,7 +114,7 @@ public class ScoredPagedMultiSearcher implements MultiSearcher {
}); });
} }
private Send<LuceneSearchResult> computeOtherResults(FirstPageResults firstResult, private LuceneSearchResult computeOtherResults(FirstPageResults firstResult,
List<IndexSearcher> indexSearchers, List<IndexSearcher> indexSearchers,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
@ -126,7 +126,7 @@ public class ScoredPagedMultiSearcher implements MultiSearcher {
Flux<LLKeyScore> nextHitsFlux = searchOtherPages(indexSearchers, queryParams, keyFieldName, secondPageInfo); Flux<LLKeyScore> nextHitsFlux = searchOtherPages(indexSearchers, queryParams, keyFieldName, secondPageInfo);
Flux<LLKeyScore> combinedFlux = firstPageHitsFlux.concatWith(nextHitsFlux); Flux<LLKeyScore> combinedFlux = firstPageHitsFlux.concatWith(nextHitsFlux);
return new LuceneSearchResult(totalHitsCount, combinedFlux, onClose).send(); return new LuceneSearchResult(totalHitsCount, combinedFlux, onClose);
} }
/** /**

View File

@ -33,7 +33,7 @@ public class SortedScoredFullMultiSearcher implements MultiSearcher {
} }
@Override @Override
public Mono<Send<LuceneSearchResult>> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, public Mono<LuceneSearchResult> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -94,7 +94,7 @@ public class SortedScoredFullMultiSearcher implements MultiSearcher {
/** /**
* Compute the results, extracting useful data * Compute the results, extracting useful data
*/ */
private Mono<Send<LuceneSearchResult>> computeResults(Mono<FullDocs<LLFieldDoc>> dataMono, private Mono<LuceneSearchResult> computeResults(Mono<FullDocs<LLFieldDoc>> dataMono,
LLIndexSearchers indexSearchers, LLIndexSearchers indexSearchers,
String keyFieldName, String keyFieldName,
LocalQueryParams queryParams) { LocalQueryParams queryParams) {
@ -106,7 +106,7 @@ public class SortedScoredFullMultiSearcher implements MultiSearcher {
indexSearchers.shards(), keyFieldName, true) indexSearchers.shards(), keyFieldName, true)
.take(queryParams.limitLong(), true); .take(queryParams.limitLong(), true);
return new LuceneSearchResult(totalHitsCount, hitsFlux, indexSearchers::close).send(); return new LuceneSearchResult(totalHitsCount, hitsFlux, indexSearchers::close);
}); });
} }

View File

@ -31,7 +31,7 @@ public class UnsortedScoredFullMultiSearcher implements MultiSearcher {
} }
@Override @Override
public Mono<Send<LuceneSearchResult>> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, public Mono<LuceneSearchResult> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -98,7 +98,7 @@ public class UnsortedScoredFullMultiSearcher implements MultiSearcher {
/** /**
* Compute the results, extracting useful data * Compute the results, extracting useful data
*/ */
private Mono<Send<LuceneSearchResult>> computeResults(Mono<FullDocs<LLScoreDoc>> dataMono, private Mono<LuceneSearchResult> computeResults(Mono<FullDocs<LLScoreDoc>> dataMono,
LLIndexSearchers indexSearchers, LLIndexSearchers indexSearchers,
String keyFieldName, String keyFieldName,
LocalQueryParams queryParams) { LocalQueryParams queryParams) {
@ -110,7 +110,7 @@ public class UnsortedScoredFullMultiSearcher implements MultiSearcher {
indexSearchers.shards(), keyFieldName, true) indexSearchers.shards(), keyFieldName, true)
.take(queryParams.limitLong(), true); .take(queryParams.limitLong(), true);
return new LuceneSearchResult(totalHitsCount, hitsFlux, indexSearchers::close).send(); return new LuceneSearchResult(totalHitsCount, hitsFlux, indexSearchers::close);
}); });
} }

View File

@ -22,7 +22,7 @@ public class UnsortedUnscoredSimpleMultiSearcher implements MultiSearcher {
} }
@Override @Override
public Mono<Send<LuceneSearchResult>> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, public Mono<LuceneSearchResult> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -62,8 +62,7 @@ public class UnsortedUnscoredSimpleMultiSearcher implements MultiSearcher {
List<Flux<LLKeyScore>> resultsFluxes = new ArrayList<>(results.size()); List<Flux<LLKeyScore>> resultsFluxes = new ArrayList<>(results.size());
boolean exactTotalHitsCount = true; boolean exactTotalHitsCount = true;
long totalHitsCountValue = 0; long totalHitsCountValue = 0;
for (Send<LuceneSearchResult> resultToReceive : results) { for (LuceneSearchResult result : results) {
LuceneSearchResult result = resultToReceive.receive();
resultsToDrop.add(result); resultsToDrop.add(result);
resultsFluxes.add(result.results()); resultsFluxes.add(result.results());
exactTotalHitsCount &= result.totalHitsCount().exact(); exactTotalHitsCount &= result.totalHitsCount().exact();
@ -81,7 +80,7 @@ public class UnsortedUnscoredSimpleMultiSearcher implements MultiSearcher {
luceneSearchResult.close(); luceneSearchResult.close();
} }
indexSearchers.close(); indexSearchers.close();
}).send(); });
}); });
} }
); );

View File

@ -33,7 +33,7 @@ public class UnsortedUnscoredStreamingMultiSearcher implements MultiSearcher {
private static final Supplier<Queue<ScoreDoc>> QUEUE_SUPPLIER = Queues.get(1024); private static final Supplier<Queue<ScoreDoc>> QUEUE_SUPPLIER = Queues.get(1024);
@Override @Override
public Mono<Send<LuceneSearchResult>> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono, public Mono<LuceneSearchResult> collectMulti(Mono<Send<LLIndexSearchers>> indexSearchersMono,
LocalQueryParams queryParams, LocalQueryParams queryParams,
String keyFieldName, String keyFieldName,
LLSearchTransformer transformer) { LLSearchTransformer transformer) {
@ -105,7 +105,7 @@ public class UnsortedUnscoredStreamingMultiSearcher implements MultiSearcher {
.skip(queryParams2.offsetLong()) .skip(queryParams2.offsetLong())
.take(queryParams2.limitLong(), true); .take(queryParams2.limitLong(), true);
return new LuceneSearchResult(totalHitsCount, mergedFluxes, indexSearchers::close).send(); return new LuceneSearchResult(totalHitsCount, mergedFluxes, indexSearchers::close);
}); });
}); });
}, false); }, false);

View File

@ -255,7 +255,7 @@ public class TestLuceneSearches {
runSearchers(expectedQueryType, searcher -> { runSearchers(expectedQueryType, searcher -> {
var luceneIndex = getLuceneIndex(expectedQueryType.shard(), searcher); var luceneIndex = getLuceneIndex(expectedQueryType.shard(), searcher);
var query = queryParamsBuilder.build(); var query = queryParamsBuilder.build();
try (var results = run(luceneIndex.search(query)).receive()) { try (var results = run(luceneIndex.search(query))) {
var hits = results.totalHitsCount(); var hits = results.totalHitsCount();
var keys = getResults(results); var keys = getResults(results);
if (hits.exact()) { if (hits.exact()) {
@ -267,7 +267,7 @@ public class TestLuceneSearches {
var officialSearcher = new OfficialSearcher(ENV); var officialSearcher = new OfficialSearcher(ENV);
luceneIndex = getLuceneIndex(expectedQueryType.shard(), officialSearcher); luceneIndex = getLuceneIndex(expectedQueryType.shard(), officialSearcher);
var officialQuery = queryParamsBuilder.limit(ELEMENTS.size() * 2L).build(); var officialQuery = queryParamsBuilder.limit(ELEMENTS.size() * 2L).build();
try (var officialResults = run(luceneIndex.search(officialQuery)).receive()) { try (var officialResults = run(luceneIndex.search(officialQuery))) {
var officialHits = officialResults.totalHitsCount(); var officialHits = officialResults.totalHitsCount();
var officialKeys = getResults(officialResults).stream().toList(); var officialKeys = getResults(officialResults).stream().toList();
if (officialHits.exact()) { if (officialHits.exact()) {