Check if accessible

This commit is contained in:
Andrea Cavalli 2022-06-05 16:38:39 +02:00
parent 956f33fb6c
commit cc9306fbde
8 changed files with 48 additions and 12 deletions

View File

@ -73,9 +73,13 @@ public class CountMultiSearcher implements MultiSearcher {
return new LuceneSearchResult(totalHitsCount, mergedFluxes, () -> {
for (LuceneSearchResult luceneSearchResult : resultsToDrop) {
luceneSearchResult.close();
if (luceneSearchResult.isAccessible()) {
luceneSearchResult.close();
}
}
if (indexSearchers.isAccessible()) {
indexSearchers.close();
}
indexSearchers.close();
});
});
}, false));

View File

@ -54,8 +54,16 @@ public class PagedLocalSearcher implements LocalSearcher {
.transform(firstPageTopDocsMono -> this.computeFirstPageResults(firstPageTopDocsMono, indexSearchers.shards(),
keyFieldName, queryParams2))
// Compute other results
.transform(firstResult -> this.computeOtherResults(firstResult, indexSearchers.shards(), queryParams2,
keyFieldName, indexSearchers::close))
.transform(firstResult -> this.computeOtherResults(firstResult,
indexSearchers.shards(),
queryParams2,
keyFieldName,
() -> {
if (indexSearchers.isAccessible()) {
indexSearchers.close();
}
}
))
// Ensure that one LuceneSearchResult is always returned
.single()
);

View File

@ -62,8 +62,16 @@ public class ScoredPagedMultiSearcher implements MultiSearcher {
.transform(firstPageTopDocsMono -> this.computeFirstPageResults(firstPageTopDocsMono, indexSearchers,
keyFieldName, queryParams2))
// Compute other results
.map(firstResult -> this.computeOtherResults(firstResult, indexSearchers.shards(),
queryParams2, keyFieldName, indexSearchers::close))
.map(firstResult -> this.computeOtherResults(firstResult,
indexSearchers.shards(),
queryParams2,
keyFieldName,
() -> {
if (indexSearchers.isAccessible()) {
indexSearchers.close();
}
}
))
// Ensure that one LuceneSearchResult is always returned
.single(),
false);

View File

@ -127,7 +127,9 @@ public class SortedByScoreFullMultiSearcher implements MultiSearcher {
.take(queryParams.limitLong(), true);
return new LuceneSearchResult(totalHitsCount, hitsFlux, () -> {
indexSearchers.close();
if (indexSearchers.isAccessible()) {
indexSearchers.close();
}
try {
data.close();
} catch (Exception e) {

View File

@ -121,7 +121,9 @@ public class SortedScoredFullMultiSearcher implements MultiSearcher {
.take(queryParams.limitLong(), true);
return new LuceneSearchResult(totalHitsCount, hitsFlux, () -> {
indexSearchers.close();
if (indexSearchers.isAccessible()) {
indexSearchers.close();
}
data.close();
});
});

View File

@ -143,7 +143,11 @@ public class StandardSearcher implements MultiSearcher {
.skip(queryParams.offsetLong())
.take(queryParams.limitLong(), true);
return new LuceneSearchResult(totalHitsCount, hitsFlux, indexSearchers::close);
return new LuceneSearchResult(totalHitsCount, hitsFlux, () -> {
if (indexSearchers.isAccessible()) {
indexSearchers.close();
}
});
});
}

View File

@ -53,7 +53,11 @@ public class UnsortedStreamingMultiSearcher implements MultiSearcher {
.skip(queryParams2.offsetLong())
.take(queryParams2.limitLong(), true);
return new LuceneSearchResult(totalHitsCount, mergedFluxes, indexSearchers::close);
return new LuceneSearchResult(totalHitsCount, mergedFluxes, () -> {
if (indexSearchers.isAccessible()) {
indexSearchers.close();
}
});
});
}, false);
}

View File

@ -74,9 +74,13 @@ public class UnsortedUnscoredSimpleMultiSearcher implements MultiSearcher {
return new LuceneSearchResult(totalHitsCount, mergedFluxes, () -> {
for (LuceneSearchResult luceneSearchResult : resultsToDrop) {
luceneSearchResult.close();
if (luceneSearchResult.isAccessible()) {
luceneSearchResult.close();
}
}
if (indexSearchers.isAccessible()) {
indexSearchers.close();
}
indexSearchers.close();
});
})
.doFirst(() -> {