Support more query types
This commit is contained in:
parent
8e0d806d2b
commit
89200c2ed5
@ -11,8 +11,9 @@ versions:
|
|||||||
Query: [
|
Query: [
|
||||||
BoxedQuery, TermQuery, PhraseQuery, WildcardQuery, SynonymQuery, FuzzyQuery, MatchAllDocsQuery,
|
BoxedQuery, TermQuery, PhraseQuery, WildcardQuery, SynonymQuery, FuzzyQuery, MatchAllDocsQuery,
|
||||||
MatchNoDocsQuery, BooleanQuery, SortedNumericDocValuesFieldSlowRangeQuery, SortedDocFieldExistsQuery,
|
MatchNoDocsQuery, BooleanQuery, SortedNumericDocValuesFieldSlowRangeQuery, SortedDocFieldExistsQuery,
|
||||||
ConstantScoreQuery, BoostQuery, IntPointRangeQuery, LongPointRangeQuery, IntPointExactQuery,
|
ConstantScoreQuery, BoostQuery, IntPointRangeQuery, IntNDPointRangeQuery, LongPointRangeQuery,
|
||||||
LongPointExactQuery, StandardQuery
|
LongNDPointRangeQuery, IntPointExactQuery, IntNDPointExactQuery, LongPointExactQuery, LongNDPointExactQuery,
|
||||||
|
IntPointSetQuery, LongPointSetQuery, StandardQuery
|
||||||
]
|
]
|
||||||
Occur: [OccurMust, OccurMustNot, OccurShould, OccurFilter]
|
Occur: [OccurMust, OccurMustNot, OccurShould, OccurFilter]
|
||||||
Sort: [NoSort, NumericSort, ScoreSort, DocSort, RandomSort]
|
Sort: [NoSort, NumericSort, ScoreSort, DocSort, RandomSort]
|
||||||
@ -160,22 +161,54 @@ versions:
|
|||||||
field: String
|
field: String
|
||||||
min: int
|
min: int
|
||||||
max: int
|
max: int
|
||||||
|
# Query that matches an int point field, from "min", to "max"
|
||||||
|
IntNDPointRangeQuery:
|
||||||
|
data:
|
||||||
|
field: String
|
||||||
|
min: int[]
|
||||||
|
max: int[]
|
||||||
# Query that matches a long point field, from "min", to "max"
|
# Query that matches a long point field, from "min", to "max"
|
||||||
LongPointRangeQuery:
|
LongPointRangeQuery:
|
||||||
data:
|
data:
|
||||||
field: String
|
field: String
|
||||||
min: long
|
min: long
|
||||||
max: long
|
max: long
|
||||||
|
# Query that matches a long point field, from "min", to "max"
|
||||||
|
LongNDPointRangeQuery:
|
||||||
|
data:
|
||||||
|
field: String
|
||||||
|
min: long[]
|
||||||
|
max: long[]
|
||||||
# Query that matches an int point field
|
# Query that matches an int point field
|
||||||
IntPointExactQuery:
|
IntPointExactQuery:
|
||||||
data:
|
data:
|
||||||
field: String
|
field: String
|
||||||
value: int
|
value: int
|
||||||
|
# Query that matches an int point field
|
||||||
|
IntNDPointExactQuery:
|
||||||
|
data:
|
||||||
|
field: String
|
||||||
|
value: int[]
|
||||||
# Query that matches a long point field
|
# Query that matches a long point field
|
||||||
LongPointExactQuery:
|
LongPointExactQuery:
|
||||||
data:
|
data:
|
||||||
field: String
|
field: String
|
||||||
value: long
|
value: long
|
||||||
|
# Query that matches a long point field
|
||||||
|
LongNDPointExactQuery:
|
||||||
|
data:
|
||||||
|
field: String
|
||||||
|
value: long[]
|
||||||
|
# Query that matches a set of int point field
|
||||||
|
IntPointSetQuery:
|
||||||
|
data:
|
||||||
|
field: String
|
||||||
|
values: int[]
|
||||||
|
# Query that matches a set of long point field
|
||||||
|
LongPointSetQuery:
|
||||||
|
data:
|
||||||
|
field: String
|
||||||
|
values: long[]
|
||||||
|
|
||||||
|
|
||||||
# Extra data used for parameters and the client
|
# Extra data used for parameters and the client
|
||||||
|
@ -4,10 +4,16 @@ import it.cavallium.dbengine.client.query.current.data.BooleanQueryPart;
|
|||||||
import it.cavallium.dbengine.client.query.current.data.BoostQuery;
|
import it.cavallium.dbengine.client.query.current.data.BoostQuery;
|
||||||
import it.cavallium.dbengine.client.query.current.data.BoxedQuery;
|
import it.cavallium.dbengine.client.query.current.data.BoxedQuery;
|
||||||
import it.cavallium.dbengine.client.query.current.data.ConstantScoreQuery;
|
import it.cavallium.dbengine.client.query.current.data.ConstantScoreQuery;
|
||||||
|
import it.cavallium.dbengine.client.query.current.data.IntNDPointExactQuery;
|
||||||
|
import it.cavallium.dbengine.client.query.current.data.IntNDPointRangeQuery;
|
||||||
import it.cavallium.dbengine.client.query.current.data.IntPointExactQuery;
|
import it.cavallium.dbengine.client.query.current.data.IntPointExactQuery;
|
||||||
import it.cavallium.dbengine.client.query.current.data.IntPointRangeQuery;
|
import it.cavallium.dbengine.client.query.current.data.IntPointRangeQuery;
|
||||||
|
import it.cavallium.dbengine.client.query.current.data.IntPointSetQuery;
|
||||||
|
import it.cavallium.dbengine.client.query.current.data.LongNDPointExactQuery;
|
||||||
|
import it.cavallium.dbengine.client.query.current.data.LongNDPointRangeQuery;
|
||||||
import it.cavallium.dbengine.client.query.current.data.LongPointExactQuery;
|
import it.cavallium.dbengine.client.query.current.data.LongPointExactQuery;
|
||||||
import it.cavallium.dbengine.client.query.current.data.LongPointRangeQuery;
|
import it.cavallium.dbengine.client.query.current.data.LongPointRangeQuery;
|
||||||
|
import it.cavallium.dbengine.client.query.current.data.LongPointSetQuery;
|
||||||
import it.cavallium.dbengine.client.query.current.data.NumericSort;
|
import it.cavallium.dbengine.client.query.current.data.NumericSort;
|
||||||
import it.cavallium.dbengine.client.query.current.data.PhraseQuery;
|
import it.cavallium.dbengine.client.query.current.data.PhraseQuery;
|
||||||
import it.cavallium.dbengine.client.query.current.data.SortedDocFieldExistsQuery;
|
import it.cavallium.dbengine.client.query.current.data.SortedDocFieldExistsQuery;
|
||||||
@ -78,9 +84,23 @@ public class QueryParser {
|
|||||||
case IntPointExactQuery:
|
case IntPointExactQuery:
|
||||||
var intPointExactQuery = (IntPointExactQuery) query;
|
var intPointExactQuery = (IntPointExactQuery) query;
|
||||||
return IntPoint.newExactQuery(intPointExactQuery.field(), intPointExactQuery.value());
|
return IntPoint.newExactQuery(intPointExactQuery.field(), intPointExactQuery.value());
|
||||||
|
case IntNDPointExactQuery:
|
||||||
|
var intndPointExactQuery = (IntNDPointExactQuery) query;
|
||||||
|
var intndValues = intndPointExactQuery.value().toIntArray();
|
||||||
|
return IntPoint.newRangeQuery(intndPointExactQuery.field(), intndValues, intndValues);
|
||||||
case LongPointExactQuery:
|
case LongPointExactQuery:
|
||||||
var longPointExactQuery = (LongPointExactQuery) query;
|
var longPointExactQuery = (LongPointExactQuery) query;
|
||||||
return LongPoint.newExactQuery(longPointExactQuery.field(), longPointExactQuery.value());
|
return LongPoint.newExactQuery(longPointExactQuery.field(), longPointExactQuery.value());
|
||||||
|
case LongNDPointExactQuery:
|
||||||
|
var longndPointExactQuery = (LongNDPointExactQuery) query;
|
||||||
|
var longndValues = longndPointExactQuery.value().toLongArray();
|
||||||
|
return LongPoint.newRangeQuery(longndPointExactQuery.field(), longndValues, longndValues);
|
||||||
|
case IntPointSetQuery:
|
||||||
|
var intPointSetQuery = (IntPointSetQuery) query;
|
||||||
|
return IntPoint.newSetQuery(intPointSetQuery.field(), intPointSetQuery.values().toIntArray());
|
||||||
|
case LongPointSetQuery:
|
||||||
|
var longPointSetQuery = (LongPointSetQuery) query;
|
||||||
|
return LongPoint.newSetQuery(longPointSetQuery.field(), longPointSetQuery.values().toLongArray());
|
||||||
case TermQuery:
|
case TermQuery:
|
||||||
var termQuery = (TermQuery) query;
|
var termQuery = (TermQuery) query;
|
||||||
return new org.apache.lucene.search.TermQuery(toTerm(termQuery.term()));
|
return new org.apache.lucene.search.TermQuery(toTerm(termQuery.term()));
|
||||||
@ -106,12 +126,24 @@ public class QueryParser {
|
|||||||
intPointRangeQuery.min(),
|
intPointRangeQuery.min(),
|
||||||
intPointRangeQuery.max()
|
intPointRangeQuery.max()
|
||||||
);
|
);
|
||||||
|
case IntNDPointRangeQuery:
|
||||||
|
var intndPointRangeQuery = (IntNDPointRangeQuery) query;
|
||||||
|
return IntPoint.newRangeQuery(intndPointRangeQuery.field(),
|
||||||
|
intndPointRangeQuery.min().toIntArray(),
|
||||||
|
intndPointRangeQuery.max().toIntArray()
|
||||||
|
);
|
||||||
case LongPointRangeQuery:
|
case LongPointRangeQuery:
|
||||||
var longPointRangeQuery = (LongPointRangeQuery) query;
|
var longPointRangeQuery = (LongPointRangeQuery) query;
|
||||||
return LongPoint.newRangeQuery(longPointRangeQuery.field(),
|
return LongPoint.newRangeQuery(longPointRangeQuery.field(),
|
||||||
longPointRangeQuery.min(),
|
longPointRangeQuery.min(),
|
||||||
longPointRangeQuery.max()
|
longPointRangeQuery.max()
|
||||||
);
|
);
|
||||||
|
case LongNDPointRangeQuery:
|
||||||
|
var longndPointRangeQuery = (LongNDPointRangeQuery) query;
|
||||||
|
return LongPoint.newRangeQuery(longndPointRangeQuery.field(),
|
||||||
|
longndPointRangeQuery.min().toLongArray(),
|
||||||
|
longndPointRangeQuery.max().toLongArray()
|
||||||
|
);
|
||||||
case MatchAllDocsQuery:
|
case MatchAllDocsQuery:
|
||||||
return new MatchAllDocsQuery();
|
return new MatchAllDocsQuery();
|
||||||
case MatchNoDocsQuery:
|
case MatchNoDocsQuery:
|
||||||
|
@ -45,14 +45,42 @@ public class LLItem {
|
|||||||
this.data = Longs.toByteArray(data);
|
this.data = Longs.toByteArray(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LLItem(LLType type, String name, int... data) {
|
||||||
|
this.type = type;
|
||||||
|
this.name = name;
|
||||||
|
var ba = new byte[data.length * Integer.BYTES];
|
||||||
|
for (int i = 0; i < data.length; i++) {
|
||||||
|
System.arraycopy(Ints.toByteArray(data[i]), 0, ba, i * Integer.BYTES, Integer.BYTES);
|
||||||
|
}
|
||||||
|
this.data = ba;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LLItem(LLType type, String name, long... data) {
|
||||||
|
this.type = type;
|
||||||
|
this.name = name;
|
||||||
|
var ba = new byte[data.length * Long.BYTES];
|
||||||
|
for (int i = 0; i < data.length; i++) {
|
||||||
|
System.arraycopy(Longs.toByteArray(data[i]), 0, ba, i * Long.BYTES, Long.BYTES);
|
||||||
|
}
|
||||||
|
this.data = ba;
|
||||||
|
}
|
||||||
|
|
||||||
public static LLItem newIntPoint(String name, int data) {
|
public static LLItem newIntPoint(String name, int data) {
|
||||||
return new LLItem(LLType.IntPoint, name, data);
|
return new LLItem(LLType.IntPoint, name, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LLItem newIntPointND(String name, int... data) {
|
||||||
|
return new LLItem(LLType.IntPointND, name, data);
|
||||||
|
}
|
||||||
|
|
||||||
public static LLItem newLongPoint(String name, long data) {
|
public static LLItem newLongPoint(String name, long data) {
|
||||||
return new LLItem(LLType.LongPoint, name, data);
|
return new LLItem(LLType.LongPoint, name, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LLItem newLongPointND(String name, long... data) {
|
||||||
|
return new LLItem(LLType.LongPointND, name, data);
|
||||||
|
}
|
||||||
|
|
||||||
public static LLItem newLongStoredField(String name, long data) {
|
public static LLItem newLongStoredField(String name, long data) {
|
||||||
return new LLItem(LLType.LongStoredField, name, data);
|
return new LLItem(LLType.LongStoredField, name, data);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ public enum LLType {
|
|||||||
StringFieldStored,
|
StringFieldStored,
|
||||||
IntPoint,
|
IntPoint,
|
||||||
LongPoint,
|
LongPoint,
|
||||||
|
IntPointND,
|
||||||
|
LongPointND,
|
||||||
LongStoredField,
|
LongStoredField,
|
||||||
FloatPoint,
|
FloatPoint,
|
||||||
NumericDocValuesField,
|
NumericDocValuesField,
|
||||||
|
@ -18,17 +18,12 @@ import io.net5.buffer.api.bytebuffer.ByteBufferMemoryManager;
|
|||||||
import io.net5.buffer.api.internal.Statics;
|
import io.net5.buffer.api.internal.Statics;
|
||||||
import io.net5.buffer.api.unsafe.UnsafeMemoryManager;
|
import io.net5.buffer.api.unsafe.UnsafeMemoryManager;
|
||||||
import io.net5.util.IllegalReferenceCountException;
|
import io.net5.util.IllegalReferenceCountException;
|
||||||
import io.net5.util.internal.PlatformDependent;
|
|
||||||
import it.cavallium.dbengine.database.collections.DatabaseStage;
|
|
||||||
import it.cavallium.dbengine.database.disk.LLLocalKeyValueDatabase;
|
|
||||||
import it.cavallium.dbengine.database.disk.MemorySegmentUtils;
|
|
||||||
import it.cavallium.dbengine.database.disk.UpdateAtomicResultCurrent;
|
import it.cavallium.dbengine.database.disk.UpdateAtomicResultCurrent;
|
||||||
import it.cavallium.dbengine.database.disk.UpdateAtomicResultDelta;
|
import it.cavallium.dbengine.database.disk.UpdateAtomicResultDelta;
|
||||||
import it.cavallium.dbengine.database.disk.UpdateAtomicResultPrevious;
|
import it.cavallium.dbengine.database.disk.UpdateAtomicResultPrevious;
|
||||||
import it.cavallium.dbengine.database.serialization.SerializationException;
|
import it.cavallium.dbengine.database.serialization.SerializationException;
|
||||||
import it.cavallium.dbengine.database.serialization.SerializationFunction;
|
import it.cavallium.dbengine.database.serialization.SerializationFunction;
|
||||||
import it.cavallium.dbengine.lucene.RandomSortField;
|
import it.cavallium.dbengine.lucene.RandomSortField;
|
||||||
import it.cavallium.dbengine.lucene.collector.LMDBFullFieldDocCollector;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -40,7 +35,6 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.ToIntFunction;
|
import java.util.function.ToIntFunction;
|
||||||
@ -71,8 +65,6 @@ import reactor.core.publisher.Flux;
|
|||||||
import reactor.core.publisher.Hooks;
|
import reactor.core.publisher.Hooks;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import reactor.core.scheduler.Schedulers;
|
import reactor.core.scheduler.Schedulers;
|
||||||
import reactor.util.function.Tuple2;
|
|
||||||
import reactor.util.function.Tuple3;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class LLUtils {
|
public class LLUtils {
|
||||||
@ -212,7 +204,9 @@ public class LLUtils {
|
|||||||
private static Field toField(LLItem item) {
|
private static Field toField(LLItem item) {
|
||||||
return switch (item.getType()) {
|
return switch (item.getType()) {
|
||||||
case IntPoint -> new IntPoint(item.getName(), Ints.fromByteArray(item.getData()));
|
case IntPoint -> new IntPoint(item.getName(), Ints.fromByteArray(item.getData()));
|
||||||
|
case IntPointND -> new IntPoint(item.getName(), getIntArray(item.getData()));
|
||||||
case LongPoint -> new LongPoint(item.getName(), Longs.fromByteArray(item.getData()));
|
case LongPoint -> new LongPoint(item.getName(), Longs.fromByteArray(item.getData()));
|
||||||
|
case LongPointND -> new LongPoint(item.getName(), getLongArray(item.getData()));
|
||||||
case LongStoredField -> new StoredField(item.getName(), Longs.fromByteArray(item.getData()));
|
case LongStoredField -> new StoredField(item.getName(), Longs.fromByteArray(item.getData()));
|
||||||
case FloatPoint -> new FloatPoint(item.getName(), ByteBuffer.wrap(item.getData()).getFloat());
|
case FloatPoint -> new FloatPoint(item.getName(), ByteBuffer.wrap(item.getData()).getFloat());
|
||||||
case TextField -> new TextField(item.getName(), item.stringValue(), Field.Store.NO);
|
case TextField -> new TextField(item.getName(), item.stringValue(), Field.Store.NO);
|
||||||
@ -225,6 +219,38 @@ public class LLUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
private static int[] getIntArray(byte[] data) {
|
||||||
|
var count = data.length / Integer.BYTES;
|
||||||
|
var items = new int[count];
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
items[i] = Ints.fromBytes(data[i * Integer.BYTES],
|
||||||
|
data[i * Integer.BYTES + 1],
|
||||||
|
data[i * Integer.BYTES + 2],
|
||||||
|
data[i * Integer.BYTES + 3]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
private static long[] getLongArray(byte[] data) {
|
||||||
|
var count = data.length / Long.BYTES;
|
||||||
|
var items = new long[count];
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
items[i] = Longs.fromBytes(data[i * Long.BYTES],
|
||||||
|
data[i * Long.BYTES + 1],
|
||||||
|
data[i * Long.BYTES + 2],
|
||||||
|
data[i * Long.BYTES + 3],
|
||||||
|
data[i * Long.BYTES + 4],
|
||||||
|
data[i * Long.BYTES + 5],
|
||||||
|
data[i * Long.BYTES + 6],
|
||||||
|
data[i * Long.BYTES + 7]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
public static it.cavallium.dbengine.database.LLKeyScore toKeyScore(LLKeyScore hit) {
|
public static it.cavallium.dbengine.database.LLKeyScore toKeyScore(LLKeyScore hit) {
|
||||||
return new it.cavallium.dbengine.database.LLKeyScore(hit.docId(), hit.score(), hit.key());
|
return new it.cavallium.dbengine.database.LLKeyScore(hit.docId(), hit.score(), hit.key());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user