CavalliumDBEngine/src/main/java/it/cavallium/dbengine/lucene/searcher/LuceneSearchResult.java

69 lines
1.8 KiB
Java
Raw Normal View History

package it.cavallium.dbengine.lucene.searcher;
2022-03-16 13:47:56 +01:00
import io.netty5.buffer.api.Drop;
import io.netty5.buffer.api.Owned;
2021-08-04 01:12:39 +02:00
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
import it.cavallium.dbengine.database.LLKeyScore;
2022-03-16 13:47:56 +01:00
import io.netty5.buffer.api.internal.ResourceSupport;
2022-06-14 18:05:26 +02:00
import it.cavallium.dbengine.utils.SimpleResource;
2021-07-10 20:52:01 +02:00
import java.util.Objects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import reactor.core.publisher.Flux;
2021-07-10 20:52:01 +02:00
2022-06-14 18:05:26 +02:00
public final class LuceneSearchResult extends SimpleResource {
2021-07-10 20:52:01 +02:00
private static final Logger logger = LogManager.getLogger(LuceneSearchResult.class);
2021-07-10 20:52:01 +02:00
2022-06-29 01:14:05 +02:00
private final TotalHitsCount totalHitsCount;
private final Flux<LLKeyScore> results;
private final Runnable onClose;
2021-10-01 19:17:33 +02:00
public LuceneSearchResult(TotalHitsCount totalHitsCount, Flux<LLKeyScore> results, Runnable onClose) {
2021-07-10 20:52:01 +02:00
this.totalHitsCount = totalHitsCount;
this.results = results;
2021-10-01 19:17:33 +02:00
this.onClose = onClose;
2021-07-10 20:52:01 +02:00
}
2021-08-04 01:12:39 +02:00
public TotalHitsCount totalHitsCount() {
2022-06-14 18:05:26 +02:00
ensureOpen();
2021-07-10 20:52:01 +02:00
return totalHitsCount;
}
public Flux<LLKeyScore> results() {
2022-06-14 18:05:26 +02:00
ensureOpen();
2021-07-10 20:52:01 +02:00
return results;
}
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null || obj.getClass() != this.getClass())
return false;
var that = (LuceneSearchResult) obj;
return this.totalHitsCount == that.totalHitsCount && Objects.equals(this.results, that.results);
}
@Override
public int hashCode() {
return Objects.hash(totalHitsCount, results);
}
@Override
public String toString() {
return "LuceneSearchResult[" + "totalHitsCount=" + totalHitsCount + ", " + "results=" + results + ']';
}
@Override
2022-06-14 18:05:26 +02:00
protected void onClose() {
try {
if (onClose != null) {
onClose.run();
}
} catch (Throwable ex) {
logger.error("Failed to close onClose", ex);
}
2021-09-18 18:34:21 +02:00
}
}