Add more queries
This commit is contained in:
parent
d4bff85dc6
commit
ad67aa003c
@ -12,8 +12,11 @@ versions:
|
||||
BoxedQuery, TermQuery, PhraseQuery, WildcardQuery, SynonymQuery, FuzzyQuery, MatchAllDocsQuery,
|
||||
MatchNoDocsQuery, BooleanQuery, SortedNumericDocValuesFieldSlowRangeQuery, SortedDocFieldExistsQuery,
|
||||
ConstantScoreQuery, BoostQuery, IntPointRangeQuery, IntNDPointRangeQuery, LongPointRangeQuery,
|
||||
LongNDPointRangeQuery, IntPointExactQuery, IntNDPointExactQuery, LongPointExactQuery, LongNDPointExactQuery,
|
||||
IntPointSetQuery, LongPointSetQuery, StandardQuery
|
||||
FloatPointRangeQuery, DoublePointRangeQuery, LongNDPointRangeQuery, FloatNDPointRangeQuery,
|
||||
DoubleNDPointRangeQuery, IntPointExactQuery, IntNDPointExactQuery, LongPointExactQuery, FloatPointExactQuery,
|
||||
FloatPointExactQuery, DoublePointExactQuery, LongNDPointExactQuery, FloatNDPointExactQuery,
|
||||
DoubleNDPointExactQuery, IntPointSetQuery, LongPointSetQuery, FloatPointSetQuery, DoublePointSetQuery,
|
||||
StandardQuery
|
||||
]
|
||||
Occur: [OccurMust, OccurMustNot, OccurShould, OccurFilter]
|
||||
Sort: [NoSort, NumericSort, ScoreSort, DocSort, RandomSort]
|
||||
@ -173,12 +176,36 @@ versions:
|
||||
field: String
|
||||
min: long
|
||||
max: long
|
||||
# Query that matches a float point field, from "min", to "max"
|
||||
FloatPointRangeQuery:
|
||||
data:
|
||||
field: String
|
||||
min: float
|
||||
max: float
|
||||
# Query that matches a double point field, from "min", to "max"
|
||||
DoublePointRangeQuery:
|
||||
data:
|
||||
field: String
|
||||
min: double
|
||||
max: double
|
||||
# Query that matches a long point field, from "min", to "max"
|
||||
LongNDPointRangeQuery:
|
||||
data:
|
||||
field: String
|
||||
min: long[]
|
||||
max: long[]
|
||||
# Query that matches a float point field, from "min", to "max"
|
||||
FloatNDPointRangeQuery:
|
||||
data:
|
||||
field: String
|
||||
min: float[]
|
||||
max: float[]
|
||||
# Query that matches a double point field, from "min", to "max"
|
||||
DoubleNDPointRangeQuery:
|
||||
data:
|
||||
field: String
|
||||
min: double[]
|
||||
max: double[]
|
||||
# Query that matches an int point field
|
||||
IntPointExactQuery:
|
||||
data:
|
||||
@ -194,11 +221,31 @@ versions:
|
||||
data:
|
||||
field: String
|
||||
value: long
|
||||
# Query that matches a float point field
|
||||
FloatPointExactQuery:
|
||||
data:
|
||||
field: String
|
||||
value: float
|
||||
# Query that matches a double point field
|
||||
DoublePointExactQuery:
|
||||
data:
|
||||
field: String
|
||||
value: double
|
||||
# Query that matches a long point field
|
||||
LongNDPointExactQuery:
|
||||
data:
|
||||
field: String
|
||||
value: long[]
|
||||
# Query that matches a float point field
|
||||
FloatNDPointExactQuery:
|
||||
data:
|
||||
field: String
|
||||
value: float[]
|
||||
# Query that matches a double point field
|
||||
DoubleNDPointExactQuery:
|
||||
data:
|
||||
field: String
|
||||
value: double[]
|
||||
# Query that matches a set of int point field
|
||||
IntPointSetQuery:
|
||||
data:
|
||||
@ -209,6 +256,16 @@ versions:
|
||||
data:
|
||||
field: String
|
||||
values: long[]
|
||||
# Query that matches a set of float point field
|
||||
FloatPointSetQuery:
|
||||
data:
|
||||
field: String
|
||||
values: float[]
|
||||
# Query that matches a set of double point field
|
||||
DoublePointSetQuery:
|
||||
data:
|
||||
field: String
|
||||
values: double[]
|
||||
|
||||
|
||||
# Extra data used for parameters and the client
|
||||
|
@ -4,6 +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.BoxedQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.ConstantScoreQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.DoubleNDPointExactQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.DoubleNDPointRangeQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.DoublePointExactQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.DoublePointRangeQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.DoublePointSetQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.FloatNDPointExactQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.FloatNDPointRangeQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.FloatPointExactQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.FloatPointRangeQuery;
|
||||
import it.cavallium.dbengine.client.query.current.data.FloatPointSetQuery;
|
||||
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;
|
||||
@ -27,6 +37,8 @@ import it.cavallium.dbengine.client.query.current.data.WildcardQuery;
|
||||
import it.cavallium.dbengine.lucene.RandomSortField;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.document.DoublePoint;
|
||||
import org.apache.lucene.document.FloatPoint;
|
||||
import org.apache.lucene.document.IntPoint;
|
||||
import org.apache.lucene.document.LongPoint;
|
||||
import org.apache.lucene.document.SortedNumericDocValuesField;
|
||||
@ -91,16 +103,36 @@ public class QueryParser {
|
||||
case LongPointExactQuery:
|
||||
var longPointExactQuery = (LongPointExactQuery) query;
|
||||
return LongPoint.newExactQuery(longPointExactQuery.field(), longPointExactQuery.value());
|
||||
case FloatPointExactQuery:
|
||||
var floatPointExactQuery = (FloatPointExactQuery) query;
|
||||
return FloatPoint.newExactQuery(floatPointExactQuery.field(), floatPointExactQuery.value());
|
||||
case DoublePointExactQuery:
|
||||
var doublePointExactQuery = (DoublePointExactQuery) query;
|
||||
return DoublePoint.newExactQuery(doublePointExactQuery.field(), doublePointExactQuery.value());
|
||||
case LongNDPointExactQuery:
|
||||
var longndPointExactQuery = (LongNDPointExactQuery) query;
|
||||
var longndValues = longndPointExactQuery.value().toLongArray();
|
||||
return LongPoint.newRangeQuery(longndPointExactQuery.field(), longndValues, longndValues);
|
||||
case FloatNDPointExactQuery:
|
||||
var floatndPointExactQuery = (FloatNDPointExactQuery) query;
|
||||
var floatndValues = floatndPointExactQuery.value().toFloatArray();
|
||||
return FloatPoint.newRangeQuery(floatndPointExactQuery.field(), floatndValues, floatndValues);
|
||||
case DoubleNDPointExactQuery:
|
||||
var doublendPointExactQuery = (DoubleNDPointExactQuery) query;
|
||||
var doublendValues = doublendPointExactQuery.value().toDoubleArray();
|
||||
return DoublePoint.newRangeQuery(doublendPointExactQuery.field(), doublendValues, doublendValues);
|
||||
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 FloatPointSetQuery:
|
||||
var floatPointSetQuery = (FloatPointSetQuery) query;
|
||||
return FloatPoint.newSetQuery(floatPointSetQuery.field(), floatPointSetQuery.values().toFloatArray());
|
||||
case DoublePointSetQuery:
|
||||
var doublePointSetQuery = (DoublePointSetQuery) query;
|
||||
return DoublePoint.newSetQuery(doublePointSetQuery.field(), doublePointSetQuery.values().toDoubleArray());
|
||||
case TermQuery:
|
||||
var termQuery = (TermQuery) query;
|
||||
return new org.apache.lucene.search.TermQuery(toTerm(termQuery.term()));
|
||||
@ -138,12 +170,36 @@ public class QueryParser {
|
||||
longPointRangeQuery.min(),
|
||||
longPointRangeQuery.max()
|
||||
);
|
||||
case FloatPointRangeQuery:
|
||||
var floatPointRangeQuery = (FloatPointRangeQuery) query;
|
||||
return FloatPoint.newRangeQuery(floatPointRangeQuery.field(),
|
||||
floatPointRangeQuery.min(),
|
||||
floatPointRangeQuery.max()
|
||||
);
|
||||
case DoublePointRangeQuery:
|
||||
var doublePointRangeQuery = (DoublePointRangeQuery) query;
|
||||
return DoublePoint.newRangeQuery(doublePointRangeQuery.field(),
|
||||
doublePointRangeQuery.min(),
|
||||
doublePointRangeQuery.max()
|
||||
);
|
||||
case LongNDPointRangeQuery:
|
||||
var longndPointRangeQuery = (LongNDPointRangeQuery) query;
|
||||
return LongPoint.newRangeQuery(longndPointRangeQuery.field(),
|
||||
longndPointRangeQuery.min().toLongArray(),
|
||||
longndPointRangeQuery.max().toLongArray()
|
||||
);
|
||||
case FloatNDPointRangeQuery:
|
||||
var floatndPointRangeQuery = (FloatNDPointRangeQuery) query;
|
||||
return FloatPoint.newRangeQuery(floatndPointRangeQuery.field(),
|
||||
floatndPointRangeQuery.min().toFloatArray(),
|
||||
floatndPointRangeQuery.max().toFloatArray()
|
||||
);
|
||||
case DoubleNDPointRangeQuery:
|
||||
var doublendPointRangeQuery = (DoubleNDPointRangeQuery) query;
|
||||
return DoublePoint.newRangeQuery(doublendPointRangeQuery.field(),
|
||||
doublendPointRangeQuery.min().toDoubleArray(),
|
||||
doublendPointRangeQuery.max().toDoubleArray()
|
||||
);
|
||||
case MatchAllDocsQuery:
|
||||
return new MatchAllDocsQuery();
|
||||
case MatchNoDocsQuery:
|
||||
|
@ -1,8 +1,11 @@
|
||||
package it.cavallium.dbengine.database;
|
||||
|
||||
import com.google.common.primitives.Floats;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.common.primitives.Longs;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
@ -13,9 +16,9 @@ public class LLItem {
|
||||
|
||||
private final LLType type;
|
||||
private final String name;
|
||||
private final byte[] data;
|
||||
private final Object data;
|
||||
|
||||
public LLItem(LLType type, String name, byte[] data) {
|
||||
public LLItem(LLType type, String name, ByteBuffer data) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.data = data;
|
||||
@ -24,45 +27,49 @@ public class LLItem {
|
||||
private LLItem(LLType type, String name, String data) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.data = data.getBytes(StandardCharsets.UTF_8);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
private LLItem(LLType type, String name, int data) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.data = Ints.toByteArray(data);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
private LLItem(LLType type, String name, float data) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.data = ByteBuffer.allocate(4).putFloat(data).array();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
private LLItem(LLType type, String name, long data) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.data = Longs.toByteArray(data);
|
||||
this.data = 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;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
private LLItem(LLType type, String name, float... data) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
private LLItem(LLType type, String name, double... data) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
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;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static LLItem newIntPoint(String name, int data) {
|
||||
@ -77,16 +84,28 @@ public class LLItem {
|
||||
return new LLItem(LLType.LongPoint, name, data);
|
||||
}
|
||||
|
||||
public static LLItem newFloatPoint(String name, float data) {
|
||||
return new LLItem(LLType.FloatPoint, name, data);
|
||||
}
|
||||
|
||||
public static LLItem newDoublePoint(String name, double data) {
|
||||
return new LLItem(LLType.DoublePoint, 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) {
|
||||
return new LLItem(LLType.LongStoredField, name, data);
|
||||
public static LLItem newFloatPointND(String name, float... data) {
|
||||
return new LLItem(LLType.FloatPointND, name, data);
|
||||
}
|
||||
|
||||
public static LLItem newFloatPoint(String name, float data) {
|
||||
return new LLItem(LLType.FloatPoint, name, data);
|
||||
public static LLItem newDoublePointND(String name, double... data) {
|
||||
return new LLItem(LLType.DoublePointND, name, data);
|
||||
}
|
||||
|
||||
public static LLItem newLongStoredField(String name, long data) {
|
||||
return new LLItem(LLType.LongStoredField, name, data);
|
||||
}
|
||||
|
||||
public static LLItem newTextField(String name, String data, Field.Store store) {
|
||||
@ -121,7 +140,7 @@ public class LLItem {
|
||||
return type;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -133,31 +152,64 @@ public class LLItem {
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LLItem llItem = (LLItem) o;
|
||||
return type == llItem.type &&
|
||||
Objects.equals(name, llItem.name) &&
|
||||
Arrays.equals(data, llItem.data);
|
||||
|
||||
if (type != llItem.type) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(name, llItem.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = Objects.hash(type, name);
|
||||
result = 31 * result + Arrays.hashCode(data);
|
||||
int result = type != null ? type.hashCode() : 0;
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
var sj = new StringJoiner(", ", "[", "]")
|
||||
return new StringJoiner(", ", LLItem.class.getSimpleName() + "[", "]")
|
||||
.add("type=" + type)
|
||||
.add("name='" + name + "'");
|
||||
if (data != null && data.length > 0) {
|
||||
sj.add("data=" + new String(data));
|
||||
}
|
||||
return sj.toString();
|
||||
.add("name='" + name + "'")
|
||||
.add("data=" + data)
|
||||
.toString();
|
||||
}
|
||||
|
||||
public int intData() {
|
||||
return (int) data;
|
||||
}
|
||||
|
||||
public int[] intArrayData() {
|
||||
return (int[]) data;
|
||||
}
|
||||
|
||||
public long longData() {
|
||||
return (long) data;
|
||||
}
|
||||
|
||||
public long[] longArrayData() {
|
||||
return (long[]) data;
|
||||
}
|
||||
|
||||
public float floatData() {
|
||||
return (float) data;
|
||||
}
|
||||
|
||||
public float[] floatArrayData() {
|
||||
return (float[]) data;
|
||||
}
|
||||
|
||||
public double doubleData() {
|
||||
return (double) data;
|
||||
}
|
||||
|
||||
public double[] doubleArrayData() {
|
||||
return (double[]) data;
|
||||
}
|
||||
|
||||
public String stringValue() {
|
||||
return new String(data, StandardCharsets.UTF_8);
|
||||
return (String) data;
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,13 @@ public enum LLType {
|
||||
StringFieldStored,
|
||||
IntPoint,
|
||||
LongPoint,
|
||||
FloatPoint,
|
||||
DoublePoint,
|
||||
IntPointND,
|
||||
LongPointND,
|
||||
FloatPointND,
|
||||
DoublePointND,
|
||||
LongStoredField,
|
||||
FloatPoint,
|
||||
NumericDocValuesField,
|
||||
SortedNumericDocValuesField,
|
||||
TextField,
|
||||
|
@ -44,7 +44,9 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.DoublePoint;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Field.Store;
|
||||
import org.apache.lucene.document.FloatPoint;
|
||||
import org.apache.lucene.document.IntPoint;
|
||||
import org.apache.lucene.document.LongPoint;
|
||||
@ -207,23 +209,24 @@ public class LLUtils {
|
||||
|
||||
private static Field toField(LLItem item) {
|
||||
return switch (item.getType()) {
|
||||
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 LongPointND -> new LongPoint(item.getName(), getLongArray(item.getData()));
|
||||
case LongStoredField -> new StoredField(item.getName(), Longs.fromByteArray(item.getData()));
|
||||
case FloatPoint -> new FloatPoint(item.getName(), ByteBuffer.wrap(item.getData()).getFloat());
|
||||
case TextField -> new TextField(item.getName(), item.stringValue(), Field.Store.NO);
|
||||
case TextFieldStored -> new TextField(item.getName(), item.stringValue(), Field.Store.YES);
|
||||
case SortedNumericDocValuesField ->
|
||||
new SortedNumericDocValuesField(item.getName(), Longs.fromByteArray(item.getData()));
|
||||
case NumericDocValuesField -> new NumericDocValuesField(item.getName(), Longs.fromByteArray(item.getData()));
|
||||
case StringField -> new StringField(item.getName(), item.stringValue(), Field.Store.NO);
|
||||
case StringFieldStored -> new StringField(item.getName(), item.stringValue(), Field.Store.YES);
|
||||
case IntPoint -> new IntPoint(item.getName(), item.intData());
|
||||
case DoublePoint -> new DoublePoint(item.getName(), item.doubleData());
|
||||
case IntPointND -> new IntPoint(item.getName(), item.intArrayData());
|
||||
case LongPoint -> new LongPoint(item.getName(), item.longData());
|
||||
case LongPointND -> new LongPoint(item.getName(), item.longArrayData());
|
||||
case FloatPointND -> new FloatPoint(item.getName(), item.floatArrayData());
|
||||
case DoublePointND -> new DoublePoint(item.getName(), item.doubleArrayData());
|
||||
case LongStoredField -> new StoredField(item.getName(), item.longData());
|
||||
case FloatPoint -> new FloatPoint(item.getName(), item.floatData());
|
||||
case TextField -> new TextField(item.getName(), item.stringValue(), Store.NO);
|
||||
case TextFieldStored -> new TextField(item.getName(), item.stringValue(), Store.YES);
|
||||
case SortedNumericDocValuesField -> new SortedNumericDocValuesField(item.getName(), item.longData());
|
||||
case NumericDocValuesField -> new NumericDocValuesField(item.getName(), item.longData());
|
||||
case StringField -> new StringField(item.getName(), item.stringValue(), Store.NO);
|
||||
case StringFieldStored -> new StringField(item.getName(), item.stringValue(), Store.YES);
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private static int[] getIntArray(byte[] data) {
|
||||
var count = data.length / Integer.BYTES;
|
||||
var items = new int[count];
|
||||
@ -237,7 +240,6 @@ public class LLUtils {
|
||||
return items;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private static long[] getLongArray(byte[] data) {
|
||||
var count = data.length / Long.BYTES;
|
||||
var items = new long[count];
|
||||
|
Loading…
Reference in New Issue
Block a user