added missing dedicated value comparators for the different indices field data
This commit is contained in:
parent
45f27fe96a
commit
b739bf97d4
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.elasticsearch.index.fielddata.ByteValues;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class ByteValuesComparator extends FieldComparator<Byte> {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final byte missingValue;
|
||||||
|
|
||||||
|
protected final byte[] values;
|
||||||
|
private byte bottom;
|
||||||
|
private ByteValues readerValues;
|
||||||
|
|
||||||
|
public ByteValuesComparator(IndexNumericFieldData indexFieldData, byte missingValue, int numHits) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
this.values = new byte[numHits];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(int slot1, int slot2) {
|
||||||
|
final byte v1 = values[slot1];
|
||||||
|
final byte v2 = values[slot2];
|
||||||
|
if (v1 > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (v1 < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBottom(int slot) {
|
||||||
|
this.bottom = values[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareBottom(int doc) throws IOException {
|
||||||
|
byte v2 = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
|
||||||
|
if (bottom > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (bottom < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(int slot, int doc) throws IOException {
|
||||||
|
values[slot] = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<Byte> setNextReader(AtomicReaderContext context) throws IOException {
|
||||||
|
this.readerValues = indexFieldData.load(context).getByteValues();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Byte value(int slot) {
|
||||||
|
return Byte.valueOf(values[slot]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareDocToValue(int doc, Byte valueObj) throws IOException {
|
||||||
|
final byte value = valueObj.byteValue();
|
||||||
|
byte docValue = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
if (docValue < value) {
|
||||||
|
return -1;
|
||||||
|
} else if (docValue > value) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.apache.lucene.search.SortField;
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class ByteValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final Object missingValue;
|
||||||
|
|
||||||
|
public ByteValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortField.Type reducedType() {
|
||||||
|
return SortField.Type.INT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
|
||||||
|
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
|
||||||
|
|
||||||
|
byte dMissingValue;
|
||||||
|
if (missingValue == null || "_last".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Byte.MIN_VALUE : Byte.MAX_VALUE;
|
||||||
|
} else if ("_first".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Byte.MAX_VALUE : Byte.MIN_VALUE;
|
||||||
|
} else {
|
||||||
|
dMissingValue = missingValue instanceof Number ? ((Number) missingValue).byteValue() : Byte.parseByte(missingValue.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ByteValuesComparator(indexFieldData, dMissingValue, numHits);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.elasticsearch.index.fielddata.FloatValues;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class FloatValuesComparator extends FieldComparator<Float> {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final float missingValue;
|
||||||
|
|
||||||
|
protected final float[] values;
|
||||||
|
private float bottom;
|
||||||
|
private FloatValues readerValues;
|
||||||
|
|
||||||
|
public FloatValuesComparator(IndexNumericFieldData indexFieldData, float missingValue, int numHits) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
this.values = new float[numHits];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(int slot1, int slot2) {
|
||||||
|
final float v1 = values[slot1];
|
||||||
|
final float v2 = values[slot2];
|
||||||
|
if (v1 > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (v1 < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBottom(int slot) {
|
||||||
|
this.bottom = values[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareBottom(int doc) throws IOException {
|
||||||
|
float v2 = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
|
||||||
|
if (bottom > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (bottom < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(int slot, int doc) throws IOException {
|
||||||
|
values[slot] = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<Float> setNextReader(AtomicReaderContext context) throws IOException {
|
||||||
|
this.readerValues = indexFieldData.load(context).getFloatValues();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Float value(int slot) {
|
||||||
|
return Float.valueOf(values[slot]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareDocToValue(int doc, Float valueObj) throws IOException {
|
||||||
|
final float value = valueObj.floatValue();
|
||||||
|
float docValue = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
if (docValue < value) {
|
||||||
|
return -1;
|
||||||
|
} else if (docValue > value) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.apache.lucene.search.SortField;
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class FloatValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final Object missingValue;
|
||||||
|
|
||||||
|
public FloatValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortField.Type reducedType() {
|
||||||
|
return SortField.Type.FLOAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
|
||||||
|
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
|
||||||
|
|
||||||
|
float dMissingValue;
|
||||||
|
if (missingValue == null || "_last".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
|
||||||
|
} else if ("_first".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
|
||||||
|
} else {
|
||||||
|
dMissingValue = missingValue instanceof Number ? ((Number) missingValue).floatValue() : Float.parseFloat(missingValue.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FloatValuesComparator(indexFieldData, dMissingValue, numHits);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
import org.elasticsearch.index.fielddata.IntValues;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class IntValuesComparator extends FieldComparator<Integer> {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final int missingValue;
|
||||||
|
|
||||||
|
protected final int[] values;
|
||||||
|
private int bottom;
|
||||||
|
private IntValues readerValues;
|
||||||
|
|
||||||
|
public IntValuesComparator(IndexNumericFieldData indexFieldData, int missingValue, int numHits) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
this.values = new int[numHits];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(int slot1, int slot2) {
|
||||||
|
final int v1 = values[slot1];
|
||||||
|
final int v2 = values[slot2];
|
||||||
|
if (v1 > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (v1 < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBottom(int slot) {
|
||||||
|
this.bottom = values[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareBottom(int doc) throws IOException {
|
||||||
|
int v2 = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
|
||||||
|
if (bottom > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (bottom < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(int slot, int doc) throws IOException {
|
||||||
|
values[slot] = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<Integer> setNextReader(AtomicReaderContext context) throws IOException {
|
||||||
|
this.readerValues = indexFieldData.load(context).getIntValues();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer value(int slot) {
|
||||||
|
return Integer.valueOf(values[slot]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareDocToValue(int doc, Integer valueObj) throws IOException {
|
||||||
|
final int value = valueObj.intValue();
|
||||||
|
int docValue = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
if (docValue < value) {
|
||||||
|
return -1;
|
||||||
|
} else if (docValue > value) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.apache.lucene.search.SortField;
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class IntValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final Object missingValue;
|
||||||
|
|
||||||
|
public IntValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortField.Type reducedType() {
|
||||||
|
return SortField.Type.INT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
|
||||||
|
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
|
||||||
|
|
||||||
|
int dMissingValue;
|
||||||
|
if (missingValue == null || "_last".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Integer.MIN_VALUE : Integer.MAX_VALUE;
|
||||||
|
} else if ("_first".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Integer.MAX_VALUE : Integer.MIN_VALUE;
|
||||||
|
} else {
|
||||||
|
dMissingValue = missingValue instanceof Number ? ((Number) missingValue).intValue() : Integer.parseInt(missingValue.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new IntValuesComparator(indexFieldData, dMissingValue, numHits);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
import org.elasticsearch.index.fielddata.LongValues;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class LongValuesComparator extends FieldComparator<Long> {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final long missingValue;
|
||||||
|
|
||||||
|
protected final long[] values;
|
||||||
|
private long bottom;
|
||||||
|
private LongValues readerValues;
|
||||||
|
|
||||||
|
public LongValuesComparator(IndexNumericFieldData indexFieldData, long missingValue, int numHits) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
this.values = new long[numHits];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(int slot1, int slot2) {
|
||||||
|
final long v1 = values[slot1];
|
||||||
|
final long v2 = values[slot2];
|
||||||
|
if (v1 > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (v1 < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBottom(int slot) {
|
||||||
|
this.bottom = values[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareBottom(int doc) throws IOException {
|
||||||
|
long v2 = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
|
||||||
|
if (bottom > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (bottom < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(int slot, int doc) throws IOException {
|
||||||
|
values[slot] = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<Long> setNextReader(AtomicReaderContext context) throws IOException {
|
||||||
|
this.readerValues = indexFieldData.load(context).getLongValues();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long value(int slot) {
|
||||||
|
return Long.valueOf(values[slot]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareDocToValue(int doc, Long valueObj) throws IOException {
|
||||||
|
final long value = valueObj.longValue();
|
||||||
|
long docValue = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
if (docValue < value) {
|
||||||
|
return -1;
|
||||||
|
} else if (docValue > value) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.apache.lucene.search.SortField;
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class LongValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final Object missingValue;
|
||||||
|
|
||||||
|
public LongValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortField.Type reducedType() {
|
||||||
|
return SortField.Type.LONG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
|
||||||
|
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
|
||||||
|
|
||||||
|
long dMissingValue;
|
||||||
|
if (missingValue == null || "_last".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Long.MIN_VALUE : Long.MAX_VALUE;
|
||||||
|
} else if ("_first".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Long.MAX_VALUE : Long.MIN_VALUE;
|
||||||
|
} else {
|
||||||
|
dMissingValue = missingValue instanceof Number ? ((Number) missingValue).longValue() : Long.parseLong(missingValue.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LongValuesComparator(indexFieldData, dMissingValue, numHits);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
import org.elasticsearch.index.fielddata.ShortValues;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class ShortValuesComparator extends FieldComparator<Short> {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final short missingValue;
|
||||||
|
|
||||||
|
protected final short[] values;
|
||||||
|
private short bottom;
|
||||||
|
private ShortValues readerValues;
|
||||||
|
|
||||||
|
public ShortValuesComparator(IndexNumericFieldData indexFieldData, short missingValue, int numHits) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
this.values = new short[numHits];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(int slot1, int slot2) {
|
||||||
|
final short v1 = values[slot1];
|
||||||
|
final short v2 = values[slot2];
|
||||||
|
if (v1 > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (v1 < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBottom(int slot) {
|
||||||
|
this.bottom = values[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareBottom(int doc) throws IOException {
|
||||||
|
short v2 = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
|
||||||
|
if (bottom > v2) {
|
||||||
|
return 1;
|
||||||
|
} else if (bottom < v2) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(int slot, int doc) throws IOException {
|
||||||
|
values[slot] = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<Short> setNextReader(AtomicReaderContext context) throws IOException {
|
||||||
|
this.readerValues = indexFieldData.load(context).getShortValues();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Short value(int slot) {
|
||||||
|
return Short.valueOf(values[slot]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareDocToValue(int doc, Short valueObj) throws IOException {
|
||||||
|
final short value = valueObj.shortValue();
|
||||||
|
short docValue = readerValues.getValueMissing(doc, missingValue);
|
||||||
|
if (docValue < value) {
|
||||||
|
return -1;
|
||||||
|
} else if (docValue > value) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Licensed to ElasticSearch and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. ElasticSearch licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.fielddata.fieldcomparator;
|
||||||
|
|
||||||
|
import org.apache.lucene.search.FieldComparator;
|
||||||
|
import org.apache.lucene.search.SortField;
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||||
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class ShortValuesComparatorSource extends IndexFieldData.XFieldComparatorSource {
|
||||||
|
|
||||||
|
private final IndexNumericFieldData indexFieldData;
|
||||||
|
private final Object missingValue;
|
||||||
|
|
||||||
|
public ShortValuesComparatorSource(IndexNumericFieldData indexFieldData, @Nullable Object missingValue) {
|
||||||
|
this.indexFieldData = indexFieldData;
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortField.Type reducedType() {
|
||||||
|
return SortField.Type.INT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
|
||||||
|
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
|
||||||
|
|
||||||
|
short dMissingValue;
|
||||||
|
if (missingValue == null || "_last".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Short.MIN_VALUE : Short.MAX_VALUE;
|
||||||
|
} else if ("_first".equals(missingValue)) {
|
||||||
|
dMissingValue = reversed ? Short.MAX_VALUE : Short.MIN_VALUE;
|
||||||
|
} else {
|
||||||
|
dMissingValue = missingValue instanceof Number ? ((Number) missingValue).shortValue() : Short.parseShort(missingValue.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ShortValuesComparator(indexFieldData, dMissingValue, numHits);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.fielddata.*;
|
import org.elasticsearch.index.fielddata.*;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
import org.elasticsearch.index.fielddata.fieldcomparator.ByteValuesComparatorSource;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
@ -152,6 +152,6 @@ public class ByteArrayIndexFieldData extends AbstractIndexFieldData<ByteArrayAto
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
||||||
return new DoubleValuesComparatorSource(this, missingValue);
|
return new ByteValuesComparatorSource(this, missingValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.fielddata.*;
|
import org.elasticsearch.index.fielddata.*;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
import org.elasticsearch.index.fielddata.fieldcomparator.FloatValuesComparatorSource;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
@ -152,6 +152,6 @@ public class FloatArrayIndexFieldData extends AbstractIndexFieldData<FloatArrayA
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
||||||
return new DoubleValuesComparatorSource(this, missingValue);
|
return new FloatValuesComparatorSource(this, missingValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.fielddata.*;
|
import org.elasticsearch.index.fielddata.*;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
import org.elasticsearch.index.fielddata.fieldcomparator.IntValuesComparatorSource;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
@ -152,6 +152,6 @@ public class IntArrayIndexFieldData extends AbstractIndexFieldData<IntArrayAtomi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
||||||
return new DoubleValuesComparatorSource(this, missingValue);
|
return new IntValuesComparatorSource(this, missingValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.fielddata.*;
|
import org.elasticsearch.index.fielddata.*;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
import org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
@ -152,6 +152,6 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<LongArrayAto
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
||||||
return new DoubleValuesComparatorSource(this, missingValue);
|
return new LongValuesComparatorSource(this, missingValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.fielddata.*;
|
import org.elasticsearch.index.fielddata.*;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
import org.elasticsearch.index.fielddata.fieldcomparator.ShortValuesComparatorSource;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
@ -152,6 +152,6 @@ public class ShortArrayIndexFieldData extends AbstractIndexFieldData<ShortArrayA
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
public XFieldComparatorSource comparatorSource(@Nullable Object missingValue) {
|
||||||
return new DoubleValuesComparatorSource(this, missingValue);
|
return new ShortValuesComparatorSource(this, missingValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue