2020-12-07 22:15:18 +01:00
|
|
|
package it.cavallium.dbengine.database;
|
|
|
|
|
2021-11-08 11:17:52 +01:00
|
|
|
import io.net5.buffer.api.Resource;
|
2021-09-18 18:34:21 +02:00
|
|
|
import io.net5.buffer.api.Send;
|
2021-03-02 01:53:36 +01:00
|
|
|
import it.cavallium.data.generator.nativedata.Nullablefloat;
|
|
|
|
import it.cavallium.dbengine.client.query.current.data.NoSort;
|
|
|
|
import it.cavallium.dbengine.client.query.current.data.Query;
|
|
|
|
import it.cavallium.dbengine.client.query.current.data.QueryParams;
|
2021-08-04 01:12:39 +02:00
|
|
|
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
|
2021-11-19 19:03:31 +01:00
|
|
|
import it.cavallium.dbengine.lucene.collector.Buckets;
|
2021-11-18 17:13:53 +01:00
|
|
|
import it.cavallium.dbengine.lucene.searcher.BucketParams;
|
|
|
|
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
|
2021-11-19 19:03:31 +01:00
|
|
|
import java.util.List;
|
2021-05-11 21:59:05 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
2020-12-07 22:15:18 +01:00
|
|
|
import java.util.Set;
|
2021-11-19 19:03:31 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-12-07 22:15:18 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2021-01-30 19:57:50 +01:00
|
|
|
import reactor.core.publisher.Flux;
|
2020-12-07 22:15:18 +01:00
|
|
|
import reactor.core.publisher.Mono;
|
2021-01-30 19:57:50 +01:00
|
|
|
import reactor.util.function.Tuple2;
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-01-30 01:41:04 +01:00
|
|
|
public interface LLLuceneIndex extends LLSnapshottable {
|
2020-12-07 22:15:18 +01:00
|
|
|
|
|
|
|
String getLuceneIndexName();
|
|
|
|
|
2021-11-07 17:46:40 +01:00
|
|
|
Mono<Void> addDocument(LLTerm id, LLUpdateDocument doc);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-11-08 10:49:59 +01:00
|
|
|
/**
|
|
|
|
* WARNING! This operation is atomic!
|
|
|
|
* Please don't send infinite or huge documents fluxes, because they will
|
|
|
|
* be kept in ram all at once.
|
|
|
|
*/
|
2021-11-07 17:46:40 +01:00
|
|
|
Mono<Void> addDocuments(Flux<Entry<LLTerm, LLUpdateDocument>> documents);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-01-30 01:41:04 +01:00
|
|
|
Mono<Void> deleteDocument(LLTerm id);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-11-07 17:46:40 +01:00
|
|
|
Mono<Void> update(LLTerm id, LLIndexRequest request);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-11-07 17:46:40 +01:00
|
|
|
Mono<Void> updateDocuments(Mono<Map<LLTerm, LLUpdateDocument>> documents);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-01-30 01:41:04 +01:00
|
|
|
Mono<Void> deleteAll();
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2020-12-08 10:52:15 +01:00
|
|
|
/**
|
2021-03-02 01:53:36 +01:00
|
|
|
* @param queryParams the limit is valid for each lucene instance. If you have 15 instances, the number of elements
|
|
|
|
* returned can be at most <code>limit * 15</code>.
|
|
|
|
* <p>
|
|
|
|
* The additional query will be used with the moreLikeThis query: "mltQuery AND additionalQuery"
|
2021-01-29 17:19:01 +01:00
|
|
|
* @return the collection has one or more flux
|
2020-12-08 10:52:15 +01:00
|
|
|
*/
|
2021-11-08 11:17:52 +01:00
|
|
|
Mono<LLSearchResultShard> moreLikeThis(@Nullable LLSnapshot snapshot,
|
2021-03-02 01:53:36 +01:00
|
|
|
QueryParams queryParams,
|
|
|
|
String keyFieldName,
|
|
|
|
Flux<Tuple2<String, Set<String>>> mltDocumentFields);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
|
|
|
/**
|
2021-03-02 01:53:36 +01:00
|
|
|
* @param queryParams the limit is valid for each lucene instance. If you have 15 instances, the number of elements
|
|
|
|
* returned can be at most <code>limit * 15</code>
|
2020-12-07 22:15:18 +01:00
|
|
|
* @return the collection has one or more flux
|
|
|
|
*/
|
2021-11-08 11:17:52 +01:00
|
|
|
Mono<LLSearchResultShard> search(@Nullable LLSnapshot snapshot, QueryParams queryParams, String keyFieldName);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-11-18 17:13:53 +01:00
|
|
|
/**
|
|
|
|
* @return buckets with each value collected into one of the buckets
|
|
|
|
*/
|
2021-11-19 19:03:31 +01:00
|
|
|
Mono<Buckets> computeBuckets(@Nullable LLSnapshot snapshot,
|
|
|
|
@NotNull List<Query> queries,
|
|
|
|
@Nullable Query normalizationQuery,
|
|
|
|
BucketParams bucketParams);
|
2021-11-18 17:13:53 +01:00
|
|
|
|
2021-08-04 01:12:39 +02:00
|
|
|
default Mono<TotalHitsCount> count(@Nullable LLSnapshot snapshot, Query query) {
|
2021-12-12 23:40:30 +01:00
|
|
|
QueryParams params = QueryParams.of(query, 0, 0, Nullablefloat.empty(), NoSort.of(), false, Long.MAX_VALUE);
|
2021-03-03 15:03:25 +01:00
|
|
|
return Mono.from(this.search(snapshot, params, null)
|
2021-11-08 11:17:52 +01:00
|
|
|
.map(llSearchResultShard -> {
|
|
|
|
try (llSearchResultShard) {
|
2021-09-18 18:34:21 +02:00
|
|
|
return llSearchResultShard.totalHitsCount();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.defaultIfEmpty(TotalHitsCount.of(0, true))
|
2022-01-26 14:22:54 +01:00
|
|
|
);
|
2021-01-30 01:41:04 +01:00
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
|
|
|
|
boolean isLowMemoryMode();
|
2021-01-30 01:41:04 +01:00
|
|
|
|
|
|
|
Mono<Void> close();
|
2021-02-03 13:48:30 +01:00
|
|
|
|
|
|
|
/**
|
2021-11-20 01:30:06 +01:00
|
|
|
* Flush writes to disk.
|
|
|
|
* This does not commit, it syncs the data to the disk
|
2021-02-03 13:48:30 +01:00
|
|
|
*/
|
|
|
|
Mono<Void> flush();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh index searcher
|
|
|
|
*/
|
2021-07-18 19:37:24 +02:00
|
|
|
Mono<Void> refresh(boolean force);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|