2021-10-16 00:50:06 +02:00
|
|
|
package it.cavallium.dbengine;
|
2021-10-13 00:23:56 +02:00
|
|
|
|
|
|
|
import com.google.common.primitives.Ints;
|
|
|
|
import com.google.common.primitives.Longs;
|
|
|
|
import it.cavallium.dbengine.client.Indicizer;
|
2021-11-07 17:46:40 +01:00
|
|
|
import it.cavallium.dbengine.database.LLUpdateDocument;
|
2021-10-13 00:23:56 +02:00
|
|
|
import it.cavallium.dbengine.database.LLItem;
|
|
|
|
import it.cavallium.dbengine.database.LLTerm;
|
|
|
|
import it.cavallium.dbengine.lucene.analyzer.TextFieldsAnalyzer;
|
|
|
|
import it.cavallium.dbengine.lucene.analyzer.TextFieldsSimilarity;
|
2022-03-05 15:46:40 +01:00
|
|
|
import it.cavallium.dbengine.rpc.current.data.IndicizerAnalyzers;
|
|
|
|
import it.cavallium.dbengine.rpc.current.data.IndicizerSimilarities;
|
2021-10-13 00:23:56 +02:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import org.apache.lucene.document.Field;
|
|
|
|
import org.apache.lucene.document.Field.Store;
|
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-10-13 00:23:56 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
public class StringIndicizer extends Indicizer<String, String> {
|
|
|
|
|
|
|
|
@Override
|
2021-11-07 17:46:40 +01:00
|
|
|
public @NotNull Mono<LLUpdateDocument> toIndexRequest(@NotNull String key, @NotNull String value) {
|
2021-10-13 00:23:56 +02:00
|
|
|
return Mono.fromCallable(() -> {
|
|
|
|
var fields = new LinkedList<LLItem>();
|
|
|
|
fields.add(LLItem.newStringField("uid", key, Field.Store.YES));
|
|
|
|
fields.add(LLItem.newTextField("text", value, Store.NO));
|
|
|
|
@SuppressWarnings("UnstableApiUsage")
|
|
|
|
var numInt = Ints.tryParse(value);
|
|
|
|
if (numInt != null) {
|
|
|
|
fields.add(LLItem.newIntPoint("intpoint", numInt));
|
2021-11-20 16:09:00 +01:00
|
|
|
fields.add(LLItem.newNumericDocValuesField("intsort", numInt));
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
@SuppressWarnings("UnstableApiUsage")
|
|
|
|
var numLong = Longs.tryParse(value);
|
|
|
|
if (numLong != null) {
|
|
|
|
fields.add(LLItem.newLongPoint("longpoint", numLong));
|
2021-11-20 16:09:00 +01:00
|
|
|
fields.add(LLItem.newNumericDocValuesField("longsort", numLong));
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
2022-03-18 19:16:06 +01:00
|
|
|
return new LLUpdateDocument(fields);
|
2021-10-13 00:23:56 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NotNull LLTerm toIndex(@NotNull String key) {
|
|
|
|
return new LLTerm("uid", key);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NotNull String getKeyFieldName() {
|
|
|
|
return "uid";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-03-10 01:43:37 +01:00
|
|
|
public @NotNull String getKey(IndexableField key) {
|
|
|
|
return key.stringValue();
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IndicizerAnalyzers getPerFieldAnalyzer() {
|
2022-03-05 15:46:40 +01:00
|
|
|
return it.cavallium.dbengine.client.IndicizerAnalyzers.of(TextFieldsAnalyzer.ICUCollationKey);
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IndicizerSimilarities getPerFieldSimilarity() {
|
2022-03-05 15:46:40 +01:00
|
|
|
return it.cavallium.dbengine.client.IndicizerSimilarities.of(TextFieldsSimilarity.BM25Standard);
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
}
|