Update DatabaseMemoryMode.java, Indicizer.java, and 3 more files...
This commit is contained in:
parent
490d15413e
commit
ef43bbe5fe
@ -0,0 +1,5 @@
|
||||
package it.cavallium.dbengine.database.indicizer;
|
||||
|
||||
public enum DatabaseMemoryMode {
|
||||
LOW, NORMAL, HIGH
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package it.cavallium.dbengine.database.indicizer;
|
||||
|
||||
import it.cavallium.dbengine.database.LLDocument;
|
||||
import it.cavallium.dbengine.database.LLTerm;
|
||||
import java.util.Set;
|
||||
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> {
|
||||
|
||||
public abstract @NotNull Mono<LLDocument> toDocument(@NotNull T key, @NotNull U value);
|
||||
|
||||
public abstract @NotNull LLTerm toIndex(@NotNull T key);
|
||||
|
||||
public abstract @NotNull String getKeyFieldName();
|
||||
|
||||
public abstract @NotNull T getKey(String key);
|
||||
|
||||
public Flux<Tuple2<String, Set<String>>> getMoreLikeThisDocumentFields(U value) {
|
||||
return Flux.empty();
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package it.cavallium.dbengine.database.indicizer;
|
||||
|
||||
import it.cavallium.dbengine.database.LLScoreMode;
|
||||
import it.cavallium.dbengine.database.LLSearchResult;
|
||||
import it.cavallium.dbengine.database.LLSort;
|
||||
import it.cavallium.dbengine.database.collections.Joiner;
|
||||
import it.cavallium.dbengine.database.collections.Joiner.ValueGetter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import it.cavallium.dbengine.client.CompositeSnapshot;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class JoinedIndicizerWriter<KEY, DBTYPE, JOINEDTYPE> implements LuceneIndicizerWriter<KEY, DBTYPE> {
|
||||
|
||||
private final LuceneIndicizerWriter<KEY, JOINEDTYPE> indicizerWriter;
|
||||
private final Joiner<KEY, DBTYPE, JOINEDTYPE> joiner;
|
||||
private final ValueGetter<KEY, DBTYPE> dbValueGetter;
|
||||
|
||||
public JoinedIndicizerWriter(LuceneIndicizerWriter<KEY, JOINEDTYPE> indicizerWriter,
|
||||
Joiner<KEY, DBTYPE, JOINEDTYPE> joiner,
|
||||
ValueGetter<KEY, DBTYPE> dbValueGetter) {
|
||||
this.indicizerWriter = indicizerWriter;
|
||||
this.joiner = joiner;
|
||||
this.dbValueGetter = dbValueGetter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> add(KEY key, DBTYPE value) {
|
||||
return joiner
|
||||
.join(dbValueGetter, value)
|
||||
.flatMap(joinedValue -> this.indicizerWriter.add(key, joinedValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> remove(KEY key) {
|
||||
return this.indicizerWriter.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> update(KEY key, DBTYPE value) {
|
||||
return joiner
|
||||
.join(dbValueGetter, value)
|
||||
.flatMap(joinedValue -> this.indicizerWriter.update(key, joinedValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> clearIndex() {
|
||||
return this.indicizerWriter.clearIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<LLSearchResult> moreLikeThis(@Nullable CompositeSnapshot snapshot, DBTYPE mltDocumentValue, int limit) {
|
||||
return joiner
|
||||
.join(dbValueGetter, mltDocumentValue)
|
||||
.flatMap(val -> this.indicizerWriter.moreLikeThis(snapshot, val, limit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<LLSearchResult> search(@Nullable CompositeSnapshot snapshot,
|
||||
String query,
|
||||
int limit,
|
||||
@Nullable LLSort sort,
|
||||
LLScoreMode scoreMode) {
|
||||
return this.indicizerWriter
|
||||
.search(snapshot, query, limit, sort, scoreMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Long> count(@Nullable CompositeSnapshot snapshot, String query) {
|
||||
return this.indicizerWriter.count(snapshot, query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> close() {
|
||||
return this.indicizerWriter.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<KEY> getKey(String key) {
|
||||
return this.indicizerWriter.getKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseMemoryMode getMemoryMode() {
|
||||
return this.indicizerWriter.getMemoryMode();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package it.cavallium.dbengine.database.indicizer;
|
||||
|
||||
import it.cavallium.dbengine.client.CompositeSnapshot;
|
||||
import it.cavallium.dbengine.database.LLScoreMode;
|
||||
import it.cavallium.dbengine.database.LLSearchResult;
|
||||
import it.cavallium.dbengine.database.LLSort;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
|
||||
public interface LuceneIndicizerWriter<T, U> {
|
||||
|
||||
Mono<Void> add(T key, U value);
|
||||
|
||||
default Mono<Void> addMulti(@NotNull Flux<Tuple2<T, U>> values) {
|
||||
return values.flatMap(tuple -> this.add(tuple.getT1(), tuple.getT2())).then();
|
||||
}
|
||||
|
||||
Mono<Void> remove(T key);
|
||||
|
||||
Mono<Void> update(T key, U value);
|
||||
|
||||
default Mono<Void> updateMulti(@NotNull Flux<Tuple2<T, U>> values) {
|
||||
return values.flatMap(tuple -> this.update(tuple.getT1(), tuple.getT2())).then();
|
||||
}
|
||||
|
||||
Mono<Void> clearIndex();
|
||||
|
||||
Mono<LLSearchResult> moreLikeThis(@Nullable CompositeSnapshot snapshot,
|
||||
U mltDocumentValue,
|
||||
int limit);
|
||||
|
||||
Mono<LLSearchResult> search(@Nullable CompositeSnapshot snapshot,
|
||||
String query,
|
||||
int limit,
|
||||
@Nullable LLSort sort,
|
||||
LLScoreMode scoreMode);
|
||||
|
||||
Mono<Long> count(@Nullable CompositeSnapshot snapshot, String query);
|
||||
|
||||
Mono<Void> close();
|
||||
|
||||
Mono<T> getKey(String key);
|
||||
|
||||
DatabaseMemoryMode getMemoryMode();
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package it.cavallium.dbengine.database.indicizer;
|
||||
|
||||
import it.cavallium.dbengine.database.LLLuceneIndex;
|
||||
import it.cavallium.dbengine.database.LLScoreMode;
|
||||
import it.cavallium.dbengine.database.LLSearchResult;
|
||||
import it.cavallium.dbengine.database.LLSnapshot;
|
||||
import it.cavallium.dbengine.database.LLSort;
|
||||
import it.cavallium.dbengine.database.LLTerm;
|
||||
import java.util.Set;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import it.cavallium.dbengine.client.CompositeSnapshot;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
|
||||
public class StandardLuceneIndicizerWriter<T, U> implements LuceneIndicizerWriter<T, U> {
|
||||
|
||||
protected final LLLuceneIndex luceneIndex;
|
||||
protected final Indicizer<T, U> indicizer;
|
||||
|
||||
public StandardLuceneIndicizerWriter(@NotNull LLLuceneIndex luceneIndex, @NotNull Indicizer<T, U> indicizer) {
|
||||
this.luceneIndex = luceneIndex;
|
||||
this.indicizer = indicizer;
|
||||
}
|
||||
|
||||
private LLSnapshot resolveSnapshot(CompositeSnapshot snapshot) {
|
||||
if (snapshot == null) {
|
||||
return null;
|
||||
} else {
|
||||
return snapshot.getSnapshot(luceneIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> add(@NotNull T key, @NotNull U value) {
|
||||
LLTerm docKey = indicizer.toIndex(key);
|
||||
return indicizer.toDocument(key, value).flatMap(doc -> luceneIndex.addDocument(docKey, doc));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> remove(@NotNull T key) {
|
||||
LLTerm term = indicizer.toIndex(key);
|
||||
return luceneIndex.deleteDocument(term);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> update(@NotNull T key, @NotNull U value) {
|
||||
LLTerm term = indicizer.toIndex(key);
|
||||
return indicizer.toDocument(key, value).flatMap(doc -> luceneIndex.updateDocument(term, doc));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> clearIndex() {
|
||||
return luceneIndex.deleteAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<LLSearchResult> moreLikeThis(@Nullable CompositeSnapshot snapshot, U mltDocumentValue, int limit) {
|
||||
Flux<Tuple2<String, Set<String>>> mltDocumentFields = indicizer.getMoreLikeThisDocumentFields(mltDocumentValue);
|
||||
return luceneIndex.moreLikeThis(resolveSnapshot(snapshot), mltDocumentFields, limit, indicizer.getKeyFieldName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<LLSearchResult> search(@Nullable CompositeSnapshot snapshot,
|
||||
String query,
|
||||
int limit,
|
||||
@Nullable LLSort sort,
|
||||
LLScoreMode scoreMode) {
|
||||
return luceneIndex.search(resolveSnapshot(snapshot), query, limit, sort, scoreMode, indicizer.getKeyFieldName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Long> count(@Nullable CompositeSnapshot snapshot, String query) {
|
||||
return luceneIndex.count(resolveSnapshot(snapshot), query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> close() {
|
||||
return luceneIndex.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<T> getKey(String key) {
|
||||
return Mono.just(indicizer.getKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseMemoryMode getMemoryMode() {
|
||||
return luceneIndex.isLowMemoryMode() ? DatabaseMemoryMode.LOW : DatabaseMemoryMode.NORMAL;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user