2021-02-03 20:13:17 +01:00
|
|
|
package it.cavallium.dbengine.client;
|
2021-01-30 22:09:04 +01:00
|
|
|
|
2022-01-28 19:31:25 +01:00
|
|
|
import com.google.common.collect.Multimap;
|
|
|
|
import com.google.common.collect.Multimaps;
|
2021-11-07 17:46:40 +01:00
|
|
|
import it.cavallium.dbengine.database.LLIndexRequest;
|
2021-11-07 18:34:34 +01:00
|
|
|
import it.cavallium.dbengine.database.LLSoftUpdateDocument;
|
2021-11-07 17:46:40 +01:00
|
|
|
import it.cavallium.dbengine.database.LLUpdateDocument;
|
2021-01-30 22:09:04 +01:00
|
|
|
import it.cavallium.dbengine.database.LLTerm;
|
2021-11-07 18:00:11 +01:00
|
|
|
import it.cavallium.dbengine.database.LLUpdateFields;
|
|
|
|
import it.cavallium.dbengine.database.LLUtils;
|
2022-03-05 15:46:40 +01:00
|
|
|
import it.cavallium.dbengine.rpc.current.data.IndicizerAnalyzers;
|
|
|
|
import it.cavallium.dbengine.rpc.current.data.IndicizerSimilarities;
|
2022-01-28 19:31:25 +01:00
|
|
|
import java.util.Map;
|
2021-01-30 22:09:04 +01:00
|
|
|
import java.util.Set;
|
2022-03-10 01:43:37 +01:00
|
|
|
import org.apache.lucene.index.IndexableField;
|
2022-02-25 15:46:32 +01:00
|
|
|
import org.apache.lucene.util.BytesRef;
|
2021-01-30 22:09:04 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import reactor.core.publisher.Flux;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
import reactor.util.function.Tuple2;
|
|
|
|
|
|
|
|
public abstract class Indicizer<T, U> {
|
|
|
|
|
2021-11-07 17:46:40 +01:00
|
|
|
/**
|
|
|
|
* Transform a value to an IndexRequest.
|
|
|
|
*/
|
|
|
|
public abstract @NotNull Mono<? extends LLIndexRequest> toIndexRequest(@NotNull T key, @NotNull U value);
|
2021-01-30 22:09:04 +01:00
|
|
|
|
2021-11-07 18:00:11 +01:00
|
|
|
public final @NotNull Mono<LLUpdateDocument> toDocument(@NotNull T key, @NotNull U value) {
|
|
|
|
return toIndexRequest(key, value).map(req -> {
|
|
|
|
if (req instanceof LLUpdateFields updateFields) {
|
|
|
|
return new LLUpdateDocument(updateFields.items());
|
|
|
|
} else if (req instanceof LLUpdateDocument updateDocument) {
|
|
|
|
return updateDocument;
|
2021-11-07 18:34:34 +01:00
|
|
|
} else if (req instanceof LLSoftUpdateDocument softUpdateDocument) {
|
|
|
|
return new LLUpdateDocument(softUpdateDocument.items());
|
2021-11-07 18:00:11 +01:00
|
|
|
} else {
|
|
|
|
throw new UnsupportedOperationException("Unexpected request type: " + req);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-30 22:09:04 +01:00
|
|
|
public abstract @NotNull LLTerm toIndex(@NotNull T key);
|
|
|
|
|
|
|
|
public abstract @NotNull String getKeyFieldName();
|
|
|
|
|
2022-03-10 01:43:37 +01:00
|
|
|
public abstract @NotNull T getKey(IndexableField key);
|
2021-01-30 22:09:04 +01:00
|
|
|
|
2021-05-28 16:04:59 +02:00
|
|
|
public abstract IndicizerAnalyzers getPerFieldAnalyzer();
|
|
|
|
|
|
|
|
public abstract IndicizerSimilarities getPerFieldSimilarity();
|
|
|
|
|
2022-01-28 19:31:25 +01:00
|
|
|
public Multimap<String, String> getMoreLikeThisDocumentFields(T key, U value) {
|
|
|
|
return Multimaps.forMap(Map.of());
|
2021-01-30 22:09:04 +01:00
|
|
|
}
|
|
|
|
}
|