2021-07-06 00:30:14 +02:00
|
|
|
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;
|
2021-07-06 00:30:14 +02:00
|
|
|
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;
|
2021-12-17 01:48:49 +01:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2021-07-06 00:30:14 +02:00
|
|
|
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
|
|
|
|
2021-12-17 01:48:49 +01: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-08-24 11:53:19 +02:00
|
|
|
|
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 + ']';
|
|
|
|
}
|
2021-07-06 00:30:14 +02:00
|
|
|
|
2021-08-24 11:53:19 +02:00
|
|
|
@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
|
|
|
}
|
2021-07-06 00:30:14 +02:00
|
|
|
}
|