This commit is contained in:
Andrea Cavalli 2023-02-24 11:07:33 +01:00
parent 1b83c95856
commit e0d929dbaa
2 changed files with 17 additions and 6 deletions

View File

@ -1,5 +1,7 @@
package it.cavallium.dbengine.client;
import static it.cavallium.dbengine.utils.StreamUtils.toListClose;
import it.cavallium.dbengine.client.Hits.CloseableHits;
import it.cavallium.dbengine.client.Hits.LuceneHits;
import it.cavallium.dbengine.client.query.ClientQueryParams;
@ -90,13 +92,12 @@ public class LuceneIndexImpl<T, U> implements LuceneIndex<T, U> {
var mltDocumentFields
= indicizer.getMoreLikeThisDocumentFields(key, mltDocumentValue);
var results = luceneIndex
var results = toListClose(luceneIndex
.moreLikeThis(resolveSnapshot(queryParams.snapshot()),
queryParams.toQueryParams(),
indicizer.getKeyFieldName(),
mltDocumentFields
)
.toList();
));
LLSearchResultShard mergedResults = mergeResults(queryParams, results);
if (mergedResults != null) {
return mapResults(mergedResults);
@ -107,12 +108,11 @@ public class LuceneIndexImpl<T, U> implements LuceneIndex<T, U> {
@Override
public Hits<HitKey<T>> search(ClientQueryParams queryParams) {
var results = luceneIndex
var results = toListClose(luceneIndex
.search(resolveSnapshot(queryParams.snapshot()),
queryParams.toQueryParams(),
indicizer.getKeyFieldName()
)
.toList();
));
var mergedResults = mergeResults(queryParams, results);
if (mergedResults != null) {

View File

@ -10,6 +10,9 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collector;
@ -96,6 +99,14 @@ public class StreamUtils {
}
}
public static <X> X scheduleOnPool(ForkJoinPool pool, Callable<X> supplier) {
try {
return pool.submit(supplier).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
private record BatchSpliterator<E>(Spliterator<E> base, int batchSize) implements Spliterator<List<E>> {
@Override