2020-12-07 22:15:18 +01:00
|
|
|
package it.cavallium.dbengine.database;
|
|
|
|
|
2022-01-28 19:31:25 +01:00
|
|
|
import com.google.common.collect.Multimap;
|
2022-08-15 23:07:17 +02:00
|
|
|
import it.cavallium.dbengine.client.IBackuppable;
|
2021-03-02 01:53:36 +01:00
|
|
|
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;
|
2022-07-02 11:44:13 +02:00
|
|
|
import java.time.Duration;
|
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;
|
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;
|
|
|
|
|
2022-08-15 23:07:17 +02:00
|
|
|
public interface LLLuceneIndex extends LLSnapshottable, IBackuppable, SafeCloseable {
|
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
|
|
|
|
2022-03-19 00:08:23 +01:00
|
|
|
Mono<Long> addDocuments(boolean atomic, 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
|
|
|
|
2022-03-19 00:08:23 +01:00
|
|
|
Mono<Long> updateDocuments(Flux<Entry<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
|
|
|
*/
|
2022-03-05 15:46:40 +01:00
|
|
|
Flux<LLSearchResultShard> moreLikeThis(@Nullable LLSnapshot snapshot,
|
2021-03-02 01:53:36 +01:00
|
|
|
QueryParams queryParams,
|
2022-02-26 03:28:20 +01:00
|
|
|
@Nullable String keyFieldName,
|
2022-01-28 19:31:25 +01:00
|
|
|
Multimap<String, 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
|
|
|
|
*/
|
2022-03-05 15:46:40 +01:00
|
|
|
Flux<LLSearchResultShard> search(@Nullable LLSnapshot snapshot,
|
2022-02-26 03:28:20 +01:00
|
|
|
QueryParams queryParams,
|
|
|
|
@Nullable 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
|
|
|
|
2022-07-02 11:44:13 +02:00
|
|
|
default Mono<TotalHitsCount> count(@Nullable LLSnapshot snapshot, Query query, @Nullable Duration timeout) {
|
|
|
|
QueryParams params = QueryParams.of(query,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NoSort.of(),
|
|
|
|
false,
|
|
|
|
timeout == null ? Long.MAX_VALUE : timeout.toMillis()
|
2022-01-26 14:22:54 +01:00
|
|
|
);
|
2022-07-02 11:44:13 +02:00
|
|
|
return Mono
|
|
|
|
.usingWhen(this.search(snapshot, params, null).singleOrEmpty(),
|
|
|
|
llSearchResultShard -> Mono.just(llSearchResultShard.totalHitsCount()),
|
|
|
|
LLUtils::finalizeResource
|
|
|
|
)
|
|
|
|
.defaultIfEmpty(TotalHitsCount.of(0, true));
|
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
|
|
|
|
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();
|
|
|
|
|
2022-06-21 14:35:07 +02:00
|
|
|
Mono<Void> waitForMerges();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait for the latest pending merge
|
|
|
|
* This disables future merges until shutdown!
|
|
|
|
*/
|
|
|
|
Mono<Void> waitForLastMerges();
|
|
|
|
|
2021-02-03 13:48:30 +01:00
|
|
|
/**
|
|
|
|
* Refresh index searcher
|
|
|
|
*/
|
2021-07-18 19:37:24 +02:00
|
|
|
Mono<Void> refresh(boolean force);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|