remove StringValues in favor of BytesValues

This commit is contained in:
Simon Willnauer 2013-03-30 15:02:20 +01:00
parent dff2a9279c
commit fefa8da2ea
18 changed files with 188 additions and 1413 deletions

View File

@ -52,11 +52,6 @@ public interface AtomicFieldData<Script extends ScriptDocValues> {
BytesValues getHashedBytesValues();
/**
* Use a non thread safe (lightweight) view of the values as strings.
*/
StringValues getStringValues();
/**
* Returns a "scripting" based values.
*/
@ -76,10 +71,5 @@ public interface AtomicFieldData<Script extends ScriptDocValues> {
BytesValues.WithOrdinals getHashedBytesValues();
/**
* Use a non thread safe (lightweight) view of the values as strings.
*/
StringValues.WithOrdinals getStringValues();
}
}

View File

@ -19,22 +19,69 @@
package org.elasticsearch.index.fielddata;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.index.fielddata.BytesValues.Iter;
/**
*/
public abstract class AtomicGeoPointFieldData<Script extends ScriptDocValues> implements AtomicFieldData<Script> {
public abstract GeoPointValues getGeoPointValues();
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
final GeoPointValues values = getGeoPointValues();
return new BytesValues(values.isMultiValued()) {
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public BytesRef getValueScratch(int docId, BytesRef ret) {
GeoPoint value = values.getValue(docId);
if (value != null) {
ret.copyChars(GeoHashUtils.encode(value.lat(), value.lon()));
} else {
ret.length = 0;
}
return ret;
}
@Override
public Iter getIter(int docId) {
final GeoPointValues.Iter iter = values.getIter(docId);
return new BytesValues.Iter() {
private final BytesRef spare = new BytesRef();
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public BytesRef next() {
GeoPoint value = iter.next();
spare.copyChars(GeoHashUtils.encode(value.lat(), value.lon()));
return spare;
}
@Override
public int hash() {
return spare.hashCode();
}
};
}
};
}
@Override
public BytesValues getHashedBytesValues() {
return getBytesValues();
}
}

View File

@ -19,29 +19,118 @@
package org.elasticsearch.index.fielddata;
import org.apache.lucene.util.BytesRef;
/**
*/
public abstract class AtomicNumericFieldData<Script extends ScriptDocValues> implements AtomicFieldData<Script> {
private boolean isFloat;
public AtomicNumericFieldData(boolean isFloat) {
this.isFloat = isFloat;
}
public abstract LongValues getLongValues();
public abstract DoubleValues getDoubleValues();
@Override
public BytesValues getBytesValues() {
if (isFloat) {
final DoubleValues values = getDoubleValues();
return new BytesValues(values.isMultiValued()) {
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public BytesRef getValueScratch(int docId, BytesRef ret) {
if (values.hasValue(docId)) {
ret.copyChars(Double.toString(values.getValue(docId)));
} else {
ret.length = 0;
}
return ret;
}
@Override
public Iter getIter(int docId) {
final DoubleValues.Iter iter = values.getIter(docId);
return new BytesValues.Iter() {
private final BytesRef spare = new BytesRef();
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public BytesRef next() {
spare.copyChars(Double.toString(iter.next()));
return spare;
}
@Override
public int hash() {
return spare.hashCode();
}
};
}
};
} else {
final LongValues values = getLongValues();
return new BytesValues(values.isMultiValued()) {
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public BytesRef getValueScratch(int docId, BytesRef ret) {
if (values.hasValue(docId)) {
ret.copyChars(Long.toString(values.getValue(docId)));
} else {
ret.length = 0;
}
return ret;
}
@Override
public Iter getIter(int docId) {
final LongValues.Iter iter = values.getIter(docId);
return new BytesValues.Iter() {
private final BytesRef spare = new BytesRef();
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public BytesRef next() {
spare.copyChars(Long.toString(iter.next()));
return spare;
}
@Override
public int hash() {
return spare.hashCode();
}
};
}
};
}
}
@Override
public BytesValues getHashedBytesValues() {
return getBytesValues();
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.LongBased(getLongValues());
}
}

View File

@ -205,68 +205,6 @@ public abstract class BytesValues {
}
}
public static class StringBased extends BytesValues {
private final StringValues values;
private final BytesRefArrayRef arrayScratch = new BytesRefArrayRef(new BytesRef[1], 1);
private final ValueIter valueIter = new ValueIter();
public StringBased(StringValues values) {
super(values.isMultiValued());
this.values = values;
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public BytesRef getValueScratch(int docId, BytesRef ret) {
String value = values.getValue(docId);
if (value == null) {
ret.length = 0;
return ret;
}
ret.copyChars(value);
return ret;
}
@Override
public Iter getIter(int docId) {
return valueIter.reset(values.getIter(docId));
}
public static class ValueIter implements Iter {
private final BytesRef scratch = new BytesRef();
private StringValues.Iter iter;
public ValueIter reset(StringValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public BytesRef next() {
scratch.copyChars(iter.next());
return scratch;
}
@Override
public int hash() {
return scratch.hashCode();
}
}
}
/**
* Bytes values that are based on ordinals.

View File

@ -20,10 +20,11 @@
package org.elasticsearch.index.fielddata;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRef;
import org.apache.lucene.util.UnicodeUtil;
import org.elasticsearch.common.geo.GeoDistance;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.index.fielddata.util.*;
import org.joda.time.MutableDateTime;
/**
@ -33,7 +34,7 @@ import org.joda.time.MutableDateTime;
public interface ScriptDocValues {
static final ScriptDocValues EMPTY = new Empty();
static final Strings EMPTY_STRINGS = new Strings(StringValues.EMPTY);
static final Strings EMPTY_STRINGS = new Strings(BytesValues.EMPTY);
void setNextDocId(int docId);
@ -52,10 +53,11 @@ public interface ScriptDocValues {
static class Strings implements ScriptDocValues {
private final StringValues values;
private final BytesValues values;
private final CharsRef spare = new CharsRef();
private int docId;
public Strings(StringValues values) {
public Strings(BytesValues values) {
this.values = values;
}
@ -70,7 +72,12 @@ public interface ScriptDocValues {
}
public String getValue() {
return values.getValue(docId);
final BytesRef value = values.getValue(docId);
if (value != null) {
UnicodeUtil.UTF8toUTF16(value, spare);
return spare.toString();
}
return null;
}
}

View File

@ -1,424 +0,0 @@
/*
* 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;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRef;
import org.apache.lucene.util.UnicodeUtil;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals.Docs;
import org.elasticsearch.index.fielddata.util.DoubleArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
import org.elasticsearch.index.fielddata.util.LongArrayRef;
import org.elasticsearch.index.fielddata.util.StringArrayRef;
/**
*/
public interface StringValues {
static final StringValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
boolean isMultiValued();
/**
* Is there a value for this doc?
*/
boolean hasValue(int docId);
String getValue(int docId);
Iter getIter(int docId);
/**
* Go over all the possible values.
*/
void forEachValueInDoc(int docId, ValueInDocProc proc);
public static interface ValueInDocProc {
void onValue(int docId, String value);
void onMissing(int docId);
}
static interface Iter {
boolean hasNext();
String next();
static class Empty implements Iter {
public static final Empty INSTANCE = new Empty();
@Override
public boolean hasNext() {
return false;
}
@Override
public String next() {
throw new ElasticSearchIllegalStateException();
}
}
static class Single implements Iter {
public String value;
public boolean done;
public Single reset(String value) {
this.value = value;
this.done = false;
return this;
}
@Override
public boolean hasNext() {
return !done;
}
@Override
public String next() {
assert !done;
done = true;
return value;
}
}
}
static class Empty implements StringValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public String getValue(int docId) {
return null;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
static class DoubleBased implements StringValues {
private final DoubleValues values;
private final StringArrayRef arrayScratch = new StringArrayRef(new String[1], 1);
private final ValuesIter valuesIter = new ValuesIter();
public DoubleBased(DoubleValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public String getValue(int docId) {
if (!values.hasValue(docId)) {
return null;
}
return Double.toString(values.getValue(docId));
}
@Override
public Iter getIter(int docId) {
return valuesIter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
if (values.hasValue(docId)) {
final DoubleValues.Iter doubleIter = values.getIter(docId);
while(doubleIter.hasNext()) {
proc.onValue(docId, Double.toString(doubleIter.next()));
}
} else {
proc.onMissing(docId);
}
}
static class ValuesIter implements Iter {
private DoubleValues.Iter iter;
private ValuesIter reset(DoubleValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public String next() {
return Double.toString(iter.next());
}
}
}
public static class LongBased implements StringValues {
private final LongValues values;
private final ValuesIter valuesIter = new ValuesIter();
public LongBased(LongValues values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return values.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return values.hasValue(docId);
}
@Override
public String getValue(int docId) {
if (!values.hasValue(docId)) {
return null;
}
return Long.toString(values.getValue(docId));
}
@Override
public Iter getIter(int docId) {
return valuesIter.reset(values.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
if (values.hasValue(docId)) {
final LongValues.Iter longIter = values.getIter(docId);
while(longIter.hasNext()) {
proc.onValue(docId, Long.toString(longIter.next()));
}
} else {
proc.onMissing(docId);
}
}
static class ValuesIter implements Iter {
private LongValues.Iter iter;
private ValuesIter reset(LongValues.Iter iter) {
this.iter = iter;
return this;
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public String next() {
return Long.toString(iter.next());
}
}
}
public interface WithOrdinals extends StringValues {
Ordinals.Docs ordinals();
String getValueByOrd(int ord);
public static class Empty extends StringValues.Empty implements WithOrdinals {
private final Ordinals ordinals;
public Empty(Ordinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public String getValueByOrd(int ord) {
return null;
}
}
}
public static class BytesValuesWrapper implements StringValues.WithOrdinals {
private org.elasticsearch.index.fielddata.BytesValues.WithOrdinals delegate;
private final CharsRef spare = new CharsRef();
protected final Docs ordinals;
protected final StringArrayRef arrayScratch;
private final OrdinalIter iter = new OrdinalIter(this);
BytesValuesWrapper(BytesValues.WithOrdinals delegate) {
arrayScratch = new StringArrayRef(new String[delegate.isMultiValued() ? 10 : 1], delegate.isMultiValued() ? 0 : 1);
this.delegate = delegate;
this.ordinals = delegate.ordinals();
}
public static StringValues.WithOrdinals wrap(BytesValues.WithOrdinals values) {
if (values.isMultiValued()) {
return new MultiBytesValuesWrapper(values);
} else {
return new BytesValuesWrapper(values);
}
}
@Override
public String getValue(int docId) {
final BytesRef value = delegate.getValue(docId);
if (value != null) {
UnicodeUtil.UTF8toUTF16(value, spare);
return spare.toString();
}
return null;
}
@Override
public Iter getIter(int docId) {
return iter.reset(this.ordinals.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
assert !isMultiValued();
int ord = ordinals.getOrd(docId);
if (ord == 0) {
proc.onMissing(docId);
} else {
proc.onValue(docId, getValueByOrd(ord));
}
}
@Override
public Docs ordinals() {
return delegate.ordinals;
}
@Override
public String getValueByOrd(int ord) {
final BytesRef value = delegate.getValueByOrd(ord);
if (value != null) {
UnicodeUtil.UTF8toUTF16(value, spare);
return spare.toString();
}
return null;
}
@Override
public boolean isMultiValued() {
return delegate.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return delegate.hasValue(docId);
}
}
static final class MultiBytesValuesWrapper extends BytesValuesWrapper {
MultiBytesValuesWrapper(org.elasticsearch.index.fielddata.BytesValues.WithOrdinals delegate) {
super(delegate);
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
assert isMultiValued();
Ordinals.Docs.Iter iter = ordinals.getIter(docId);
int ord = iter.next();
if (ord == 0) {
proc.onMissing(docId);
} else {
do {
proc.onValue(docId, getValueByOrd(ord));
} while ((ord = iter.next()) != 0);
}
}
}
static final class OrdinalIter implements StringValues.Iter {
private Ordinals.Docs.Iter ordsIter;
private int ord;
private final StringValues.WithOrdinals values;
OrdinalIter(StringValues.WithOrdinals values) {
this.values = values;
}
public OrdinalIter reset(Ordinals.Docs.Iter ordsIter) {
this.ordsIter = ordsIter;
this.ord = ordsIter.next();
return this;
}
@Override
public boolean hasNext() {
return ord != 0;
}
@Override
public String next() {
final String valueByOrd = values.getValueByOrd(ord);
ord = ordsIter.next();
return valueByOrd;
}
}
}

View File

@ -39,6 +39,7 @@ public abstract class ByteArrayAtomicFieldData extends AtomicNumericFieldData {
protected long size = -1;
public ByteArrayAtomicFieldData(byte[] values, int numDocs) {
super(false);
this.values = values;
this.numDocs = numDocs;
}
@ -47,10 +48,11 @@ public abstract class ByteArrayAtomicFieldData extends AtomicNumericFieldData {
public int getNumDocs() {
return numDocs;
}
@Override
public void close() {
}
static class Empty extends ByteArrayAtomicFieldData {
@ -89,11 +91,6 @@ public abstract class ByteArrayAtomicFieldData extends AtomicNumericFieldData {
return BytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
@ -210,17 +207,6 @@ public abstract class ByteArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.LongBased(getLongValues());
}
@Override
public LongValues getLongValues() {
return new LongValues(values, set);
@ -314,15 +300,6 @@ public abstract class ByteArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.LongBased(getLongValues());
}
@Override
public LongValues getLongValues() {

View File

@ -23,7 +23,6 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.AtomicFieldData;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals.Docs;
@ -102,14 +101,10 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicFieldData.WithOrdi
return ordinals.isMultiValued() ? new BytesValues.MultiHashed(values, ordinals.ordinals(), hashes) : new BytesValues.SingleHashed(values, ordinals.ordinals(), hashes);
}
@Override
public StringValues.WithOrdinals getStringValues() {
return StringValues.BytesValuesWrapper.wrap(getBytesValues());
}
@Override
public ScriptDocValues.Strings getScriptValues() {
return new ScriptDocValues.Strings(getStringValues());
return new ScriptDocValues.Strings(getBytesValues());
}
static abstract class BytesValues extends org.elasticsearch.index.fielddata.BytesValues.WithOrdinals {
@ -280,11 +275,6 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicFieldData.WithOrdi
return new BytesValues.WithOrdinals.Empty(ordinals.ordinals());
}
@Override
public StringValues.WithOrdinals getStringValues() {
return new StringValues.WithOrdinals.Empty((EmptyOrdinals) ordinals);
}
@Override
public ScriptDocValues.Strings getScriptValues() {
return ScriptDocValues.EMPTY_STRINGS;

View File

@ -26,7 +26,6 @@ import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
@ -41,6 +40,7 @@ public abstract class DoubleArrayAtomicFieldData extends AtomicNumericFieldData
protected long size = -1;
public DoubleArrayAtomicFieldData(double[] values, int numDocs) {
super(true);
this.values = values;
this.numDocs = numDocs;
}
@ -90,11 +90,6 @@ public abstract class DoubleArrayAtomicFieldData extends AtomicNumericFieldData
return BytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
@ -128,15 +123,6 @@ public abstract class DoubleArrayAtomicFieldData extends AtomicNumericFieldData
return size;
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues(values, ordinals.ordinals());
}
@Override
public ScriptDocValues getScriptValues() {
@ -153,85 +139,6 @@ public abstract class DoubleArrayAtomicFieldData extends AtomicNumericFieldData
return new DoubleValues(values, ordinals.ordinals());
}
static class StringValues implements org.elasticsearch.index.fielddata.StringValues {
private final double[] values;
private final Ordinals.Docs ordinals;
private final ValuesIter valuesIter;
StringValues(double[] values, Ordinals.Docs ordinals) {
this.values = values;
this.ordinals = ordinals;
this.valuesIter = new ValuesIter(values);
}
@Override
public boolean hasValue(int docId) {
return ordinals.getOrd(docId) != 0;
}
@Override
public boolean isMultiValued() {
return ordinals.isMultiValued();
}
@Override
public String getValue(int docId) {
int ord = ordinals.getOrd(docId);
if (ord == 0) {
return null;
}
return Double.toString(values[ord]);
}
@Override
public Iter getIter(int docId) {
return valuesIter.reset(ordinals.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
Ordinals.Docs.Iter iter = ordinals.getIter(docId);
int ord = iter.next();
if (ord == 0) {
proc.onMissing(docId);
return;
}
do {
proc.onValue(docId, Double.toString(values[ord]));
} while ((ord = iter.next()) != 0);
}
static class ValuesIter implements Iter {
private final double[] values;
private Ordinals.Docs.Iter ordsIter;
private int ord;
ValuesIter(double[] values) {
this.values = values;
}
public ValuesIter reset(Ordinals.Docs.Iter ordsIter) {
this.ordsIter = ordsIter;
this.ord = ordsIter.next();
return this;
}
@Override
public boolean hasNext() {
return ord != 0;
}
@Override
public String next() {
String value = Double.toString(values[ord]);
ord = ordsIter.next();
return value;
}
}
}
static class LongValues extends org.elasticsearch.index.fielddata.LongValues.OrdBasedLongValues {
@ -300,16 +207,6 @@ public abstract class DoubleArrayAtomicFieldData extends AtomicNumericFieldData
return new ScriptDocValues.NumericDouble(getDoubleValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.DoubleBased(getDoubleValues());
}
@Override
public LongValues getLongValues() {
return new LongValues(values, set);
@ -403,11 +300,6 @@ public abstract class DoubleArrayAtomicFieldData extends AtomicNumericFieldData
}
@Override
public StringValues getStringValues() {
return new StringValues(values);
}
@Override
public LongValues getLongValues() {
return new LongValues(values);
@ -418,42 +310,6 @@ public abstract class DoubleArrayAtomicFieldData extends AtomicNumericFieldData
return new DoubleValues(values);
}
static class StringValues implements org.elasticsearch.index.fielddata.StringValues {
private final double[] values;
private final Iter.Single iter = new Iter.Single();
StringValues(double[] values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return true;
}
@Override
public String getValue(int docId) {
return Double.toString(values[docId]);
}
@Override
public Iter getIter(int docId) {
return iter.reset(Double.toString(values[docId]));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onValue(docId, Double.toString(values[docId]));
}
}
static class LongValues extends org.elasticsearch.index.fielddata.LongValues.DenseLongValues {
private final double[] values;

View File

@ -31,11 +31,9 @@ import org.apache.lucene.util.fst.FST.BytesReader;
import org.apache.lucene.util.fst.Util;
import org.elasticsearch.index.fielddata.AtomicFieldData;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals.Docs;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
/**
*/
@ -94,16 +92,12 @@ public class FSTBytesAtomicFieldData implements AtomicFieldData.WithOrdinals<Scr
return ordinals.isMultiValued() ? new BytesValues.Multi(fst, ordinals.ordinals()) : new BytesValues.Single(fst, ordinals.ordinals());
}
@Override
public StringValues.WithOrdinals getStringValues() {
assert fst != null;
return StringValues.BytesValuesWrapper.wrap(getBytesValues());
}
@Override
public ScriptDocValues.Strings getScriptValues() {
assert fst != null;
return new ScriptDocValues.Strings(getStringValues());
return new ScriptDocValues.Strings(getBytesValues());
}
@Override
@ -272,11 +266,6 @@ public class FSTBytesAtomicFieldData implements AtomicFieldData.WithOrdinals<Scr
return new BytesValues.WithOrdinals.Empty(ordinals.ordinals());
}
@Override
public StringValues.WithOrdinals getStringValues() {
return new StringValues.WithOrdinals.Empty(ordinals);
}
@Override
public ScriptDocValues.Strings getScriptValues() {
return ScriptDocValues.EMPTY_STRINGS;

View File

@ -39,6 +39,7 @@ public abstract class FloatArrayAtomicFieldData extends AtomicNumericFieldData {
protected long size = -1;
public FloatArrayAtomicFieldData(float[] values, int numDocs) {
super(true);
this.values = values;
this.numDocs = numDocs;
}
@ -88,11 +89,6 @@ public abstract class FloatArrayAtomicFieldData extends AtomicNumericFieldData {
return BytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
@ -126,11 +122,6 @@ public abstract class FloatArrayAtomicFieldData extends AtomicNumericFieldData {
return size;
}
@Override
public StringValues getStringValues() {
return new StringValues.DoubleBased(getDoubleValues());
}
@Override
public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericDouble(getDoubleValues());
@ -213,15 +204,6 @@ public abstract class FloatArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericDouble(getDoubleValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.DoubleBased(getDoubleValues());
}
@Override
public LongValues getLongValues() {
@ -317,16 +299,6 @@ public abstract class FloatArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericDouble(getDoubleValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.DoubleBased(getDoubleValues());
}
@Override
public LongValues getLongValues() {
return new LongValues(values);

View File

@ -92,11 +92,6 @@ public abstract class GeoPointDoubleArrayAtomicFieldData extends AtomicGeoPointF
return GeoPointValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
@ -130,104 +125,11 @@ public abstract class GeoPointDoubleArrayAtomicFieldData extends AtomicGeoPointF
return size;
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues(lon, lat, ordinals.ordinals());
}
@Override
public GeoPointValues getGeoPointValues() {
return new GeoPointValues(lon, lat, ordinals.ordinals());
}
static class StringValues implements org.elasticsearch.index.fielddata.StringValues {
private final double[] lon;
private final double[] lat;
private final Ordinals.Docs ordinals;
private final ValuesIter valuesIter;
StringValues(double[] lon, double[] lat, Ordinals.Docs ordinals) {
this.lon = lon;
this.lat = lat;
this.ordinals = ordinals;
this.valuesIter = new ValuesIter(lon, lat);
}
@Override
public boolean isMultiValued() {
return ordinals.isMultiValued();
}
@Override
public boolean hasValue(int docId) {
return ordinals.getOrd(docId) != 0;
}
@Override
public String getValue(int docId) {
int ord = ordinals.getOrd(docId);
if (ord == 0) {
return null;
}
return GeoHashUtils.encode(lat[ord], lon[ord]);
}
@Override
public Iter getIter(int docId) {
return valuesIter.reset(ordinals.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
Ordinals.Docs.Iter iter = ordinals.getIter(docId);
int ord = iter.next();
if (ord == 0) {
proc.onMissing(docId);
return;
}
do {
proc.onValue(docId, GeoHashUtils.encode(lat[ord], lon[ord]));
} while ((ord = iter.next()) != 0);
}
static class ValuesIter implements Iter {
private final double[] lon;
private final double[] lat;
private Ordinals.Docs.Iter ordsIter;
private int ord;
ValuesIter(double[] lon, double[] lat) {
this.lon = lon;
this.lat = lat;
}
public ValuesIter reset(Ordinals.Docs.Iter ordsIter) {
this.ordsIter = ordsIter;
this.ord = ordsIter.next();
return this;
}
@Override
public boolean hasNext() {
return ord != 0;
}
@Override
public String next() {
String value = GeoHashUtils.encode(lat[ord], lon[ord]);
ord = ordsIter.next();
return value;
}
}
}
static class GeoPointValues implements org.elasticsearch.index.fielddata.GeoPointValues {
private final double[] lon;
@ -382,72 +284,11 @@ public abstract class GeoPointDoubleArrayAtomicFieldData extends AtomicGeoPointF
return size;
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues(lon, lat, set);
}
@Override
public GeoPointValues getGeoPointValues() {
return new GeoPointValues(lon, lat, set);
}
static class StringValues implements org.elasticsearch.index.fielddata.StringValues {
private final double[] lon;
private final double[] lat;
private final FixedBitSet set;
private final Iter.Single iter = new Iter.Single();
StringValues(double[] lon, double[] lat, FixedBitSet set) {
this.lon = lon;
this.lat = lat;
this.set = set;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return set.get(docId);
}
@Override
public String getValue(int docId) {
if (set.get(docId)) {
return GeoHashUtils.encode(lat[docId], lon[docId]);
} else {
return null;
}
}
@Override
public Iter getIter(int docId) {
if (set.get(docId)) {
return iter.reset(GeoHashUtils.encode(lat[docId], lon[docId]));
} else {
return Iter.Empty.INSTANCE;
}
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
if (set.get(docId)) {
proc.onValue(docId, GeoHashUtils.encode(lat[docId], lon[docId]));
} else {
proc.onMissing(docId);
}
}
}
static class GeoPointValues implements org.elasticsearch.index.fielddata.GeoPointValues {
@ -539,59 +380,12 @@ public abstract class GeoPointDoubleArrayAtomicFieldData extends AtomicGeoPointF
return size;
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues(lon, lat);
}
@Override
public GeoPointValues getGeoPointValues() {
return new GeoPointValues(lon, lat);
}
static class StringValues implements org.elasticsearch.index.fielddata.StringValues {
private final double[] lon;
private final double[] lat;
private final Iter.Single iter = new Iter.Single();
StringValues(double[] lon, double[] lat) {
this.lon = lon;
this.lat = lat;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return true;
}
@Override
public String getValue(int docId) {
return GeoHashUtils.encode(lat[docId], lon[docId]);
}
@Override
public Iter getIter(int docId) {
return iter.reset(GeoHashUtils.encode(lat[docId], lon[docId]));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onValue(docId, GeoHashUtils.encode(lat[docId], lon[docId]));
}
}
static class GeoPointValues implements org.elasticsearch.index.fielddata.GeoPointValues {
private final double[] lon;

View File

@ -26,7 +26,6 @@ import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
@ -41,6 +40,7 @@ public abstract class IntArrayAtomicFieldData extends AtomicNumericFieldData {
protected long size = -1;
public IntArrayAtomicFieldData(int[] values, int numDocs) {
super(false);
this.values = values;
this.numDocs = numDocs;
}
@ -90,11 +90,6 @@ public abstract class IntArrayAtomicFieldData extends AtomicNumericFieldData {
return BytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
@ -128,11 +123,6 @@ public abstract class IntArrayAtomicFieldData extends AtomicNumericFieldData {
return size;
}
@Override
public StringValues getStringValues() {
return new StringValues.LongBased(getLongValues());
}
@Override
public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericLong(getLongValues());
@ -217,16 +207,6 @@ public abstract class IntArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.LongBased(getLongValues());
}
@Override
public LongValues getLongValues() {
return new LongValues(values, set);
@ -319,16 +299,6 @@ public abstract class IntArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.LongBased(getLongValues());
}
@Override
public LongValues getLongValues() {
return new LongValues(values);

View File

@ -26,7 +26,6 @@ import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
@ -41,6 +40,7 @@ public abstract class LongArrayAtomicFieldData extends AtomicNumericFieldData {
protected long size = -1;
public LongArrayAtomicFieldData(long[] values, int numDocs) {
super(false);
this.values = values;
this.numDocs = numDocs;
}
@ -90,11 +90,6 @@ public abstract class LongArrayAtomicFieldData extends AtomicNumericFieldData {
return BytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
@ -128,11 +123,6 @@ public abstract class LongArrayAtomicFieldData extends AtomicNumericFieldData {
return size;
}
@Override
public StringValues getStringValues() {
return new StringValues(values, ordinals.ordinals());
}
@Override
public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericLong(getLongValues());
@ -148,85 +138,6 @@ public abstract class LongArrayAtomicFieldData extends AtomicNumericFieldData {
return new DoubleValues(values, ordinals.ordinals());
}
static class StringValues implements org.elasticsearch.index.fielddata.StringValues {
private final long[] values;
private final Ordinals.Docs ordinals;
private final ValuesIter valuesIter;
StringValues(long[] values, Ordinals.Docs ordinals) {
this.values = values;
this.ordinals = ordinals;
this.valuesIter = new ValuesIter(values);
}
@Override
public boolean hasValue(int docId) {
return ordinals.getOrd(docId) != 0;
}
@Override
public boolean isMultiValued() {
return ordinals.isMultiValued();
}
@Override
public String getValue(int docId) {
int ord = ordinals.getOrd(docId);
if (ord == 0) {
return null;
}
return Long.toString(values[ord]);
}
@Override
public Iter getIter(int docId) {
return valuesIter.reset(ordinals.getIter(docId));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
Ordinals.Docs.Iter iter = ordinals.getIter(docId);
int ord = iter.next();
if (ord == 0) {
proc.onMissing(docId);
return;
}
do {
proc.onValue(docId, Long.toString(values[ord]));
} while ((ord = iter.next()) != 0);
}
static class ValuesIter implements Iter {
private final long[] values;
private Ordinals.Docs.Iter ordsIter;
private int ord;
ValuesIter(long[] values) {
this.values = values;
}
public ValuesIter reset(Ordinals.Docs.Iter ordsIter) {
this.ordsIter = ordsIter;
this.ord = ordsIter.next();
return this;
}
@Override
public boolean hasNext() {
return ord != 0;
}
@Override
public String next() {
String value = Long.toString(values[ord]);
ord = ordsIter.next();
return value;
}
}
}
static class LongValues extends org.elasticsearch.index.fielddata.LongValues.OrdBasedLongValues {
private final long[] values;
@ -296,16 +207,6 @@ public abstract class LongArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues(values, set);
}
@Override
public LongValues getLongValues() {
return new LongValues(values, set);
@ -316,55 +217,6 @@ public abstract class LongArrayAtomicFieldData extends AtomicNumericFieldData {
return new DoubleValues(values, set);
}
static class StringValues implements org.elasticsearch.index.fielddata.StringValues {
private final long[] values;
private final FixedBitSet set;
private final Iter.Single iter = new Iter.Single();
StringValues(long[] values, FixedBitSet set) {
this.values = values;
this.set = set;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return set.get(docId);
}
@Override
public String getValue(int docId) {
if (set.get(docId)) {
return Long.toString(values[docId]);
} else {
return null;
}
}
@Override
public Iter getIter(int docId) {
if (set.get(docId)) {
return iter.reset(Long.toString(values[docId]));
} else {
return Iter.Empty.INSTANCE;
}
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
if (set.get(docId)) {
proc.onValue(docId, Long.toString(values[docId]));
} else {
proc.onMissing(docId);
}
}
}
static class LongValues extends org.elasticsearch.index.fielddata.LongValues {
private final long[] values;
@ -447,16 +299,6 @@ public abstract class LongArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues(values);
}
@Override
public LongValues getLongValues() {
return new LongValues(values);
@ -467,41 +309,6 @@ public abstract class LongArrayAtomicFieldData extends AtomicNumericFieldData {
return new DoubleValues(values);
}
static class StringValues implements org.elasticsearch.index.fielddata.StringValues {
private final long[] values;
private final Iter.Single iter = new Iter.Single();
StringValues(long[] values) {
this.values = values;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return true;
}
@Override
public String getValue(int docId) {
return Long.toString(values[docId]);
}
@Override
public Iter getIter(int docId) {
return iter.reset(Long.toString(values[docId]));
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onValue(docId, Long.toString(values[docId]));
}
}
static class LongValues extends org.elasticsearch.index.fielddata.LongValues.DenseLongValues {
private final long[] values;

View File

@ -25,14 +25,10 @@ import org.apache.lucene.util.PagedBytes.Reader;
import org.apache.lucene.util.packed.GrowableWriter;
import org.apache.lucene.util.packed.PackedInts;
import org.elasticsearch.index.fielddata.AtomicFieldData;
import org.elasticsearch.index.fielddata.BytesValues.Iter;
import org.elasticsearch.index.fielddata.BytesValues.Iter.Multi;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals.Docs;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
/**
*/
@ -117,16 +113,9 @@ public class PagedBytesAtomicFieldData implements AtomicFieldData.WithOrdinals<S
: new BytesValues.SingleHashed(hashes, bytes, termOrdToBytesOffset, ordinals.ordinals());
}
@Override
public StringValues.WithOrdinals getStringValues() {
return StringValues.BytesValuesWrapper.wrap(getBytesValues());
}
@Override
public ScriptDocValues.Strings getScriptValues() {
return new ScriptDocValues.Strings(getStringValues());
return new ScriptDocValues.Strings(getBytesValues());
}
static abstract class BytesValues extends org.elasticsearch.index.fielddata.BytesValues.WithOrdinals {
@ -279,11 +268,6 @@ public class PagedBytesAtomicFieldData implements AtomicFieldData.WithOrdinals<S
return new BytesValues.WithOrdinals.Empty(ordinals.ordinals());
}
@Override
public StringValues.WithOrdinals getStringValues() {
return new StringValues.WithOrdinals.Empty((EmptyOrdinals) ordinals);
}
@Override
public ScriptDocValues.Strings getScriptValues() {
return ScriptDocValues.EMPTY_STRINGS;

View File

@ -26,7 +26,6 @@ import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
@ -41,6 +40,7 @@ public abstract class ShortArrayAtomicFieldData extends AtomicNumericFieldData {
protected long size = -1;
public ShortArrayAtomicFieldData(short[] values, int numDocs) {
super(false);
this.values = values;
this.numDocs = numDocs;
}
@ -90,11 +90,6 @@ public abstract class ShortArrayAtomicFieldData extends AtomicNumericFieldData {
return BytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
@ -128,11 +123,6 @@ public abstract class ShortArrayAtomicFieldData extends AtomicNumericFieldData {
return size;
}
@Override
public StringValues getStringValues() {
return new StringValues.LongBased(getLongValues());
}
@Override
public ScriptDocValues getScriptValues() {
return new ScriptDocValues.NumericLong(getLongValues());
@ -217,16 +207,6 @@ public abstract class ShortArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.LongBased(getLongValues());
}
@Override
public LongValues getLongValues() {
return new LongValues(values, set);
@ -318,16 +298,6 @@ public abstract class ShortArrayAtomicFieldData extends AtomicNumericFieldData {
return new ScriptDocValues.NumericLong(getLongValues());
}
@Override
public BytesValues getBytesValues() {
return new BytesValues.StringBased(getStringValues());
}
@Override
public StringValues getStringValues() {
return new StringValues.LongBased(getLongValues());
}
@Override
public LongValues getLongValues() {
return new LongValues(values);

View File

@ -19,13 +19,6 @@
package org.elasticsearch.test.unit.index.fielddata;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.sameInstance;
import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.AtomicReader;
import org.apache.lucene.index.AtomicReaderContext;
@ -36,11 +29,9 @@ import org.apache.lucene.index.SlowCompositeReaderWrapper;
import org.apache.lucene.store.RAMDirectory;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.fielddata.StringValues;
import org.elasticsearch.index.mapper.FieldMapper;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@ -85,41 +76,4 @@ public abstract class AbstractFieldDataTests {
ifdService.clear();
}
public static class StringValuesVerifierProc implements StringValues.ValueInDocProc {
private static final String MISSING = new String();
private final int docId;
private final List<String> expected = new ArrayList<String>();
private int idx;
StringValuesVerifierProc(int docId) {
this.docId = docId;
}
public StringValuesVerifierProc addExpected(String value) {
expected.add(value);
return this;
}
public StringValuesVerifierProc addMissing() {
expected.add(MISSING);
return this;
}
@Override
public void onValue(int docId, String value) {
assertThat(docId, equalTo(this.docId));
assertThat(value, equalTo(expected.get(idx++)));
}
@Override
public void onMissing(int docId) {
assertThat(docId, equalTo(this.docId));
assertThat(MISSING, sameInstance(expected.get(idx++)));
}
}
}

View File

@ -19,24 +19,29 @@
package org.elasticsearch.test.unit.index.fielddata;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.search.*;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.AtomicFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.fieldcomparator.SortMode;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
import org.elasticsearch.index.fielddata.util.StringArrayRef;
import org.testng.annotations.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
/**
*/
@Test
@ -132,35 +137,6 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
assertThat(new HashedBytesRef(hashedBytesValuesIter.next(), hashedBytesValuesIter.hash()), equalTo(new HashedBytesRef(two())));
assertThat(hashedBytesValuesIter.hasNext(), equalTo(false));
StringValues stringValues = fieldData.getStringValues();
assertThat(stringValues.hasValue(0), equalTo(true));
assertThat(stringValues.hasValue(1), equalTo(true));
assertThat(stringValues.hasValue(2), equalTo(true));
assertThat(stringValues.getValue(0), equalTo(two()));
assertThat(stringValues.getValue(1), equalTo(one()));
assertThat(stringValues.getValue(2), equalTo(three()));
StringValues.Iter stringValuesIter = stringValues.getIter(0);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(two()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(1);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(one()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(2);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(three()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValues.forEachValueInDoc(0, new StringValuesVerifierProc(0).addExpected(two()));
stringValues.forEachValueInDoc(1, new StringValuesVerifierProc(1).addExpected(one()));
stringValues.forEachValueInDoc(2, new StringValuesVerifierProc(2).addExpected(three()));
IndexSearcher searcher = new IndexSearcher(readerContext.reader());
TopFieldDocs topDocs;
@ -260,33 +236,6 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
hashedBytesValuesIter = hashedBytesValues.getIter(1);
assertThat(hashedBytesValuesIter.hasNext(), equalTo(false));
StringValues stringValues = fieldData.getStringValues();
assertThat(stringValues.hasValue(0), equalTo(true));
assertThat(stringValues.hasValue(1), equalTo(false));
assertThat(stringValues.hasValue(2), equalTo(true));
assertThat(stringValues.getValue(0), equalTo(two()));
assertThat(stringValues.getValue(1), nullValue());
assertThat(stringValues.getValue(2), equalTo(three()));
StringValues.Iter stringValuesIter = stringValues.getIter(0);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(two()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(1);
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(2);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(three()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValues.forEachValueInDoc(0, new StringValuesVerifierProc(0).addExpected(two()));
stringValues.forEachValueInDoc(1, new StringValuesVerifierProc(1).addMissing());
stringValues.forEachValueInDoc(2, new StringValuesVerifierProc(2).addExpected(three()));
// TODO properly support missing....
}
@ -362,38 +311,6 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
assertThat(new HashedBytesRef(hashedBytesValuesIter.next(), hashedBytesValuesIter.hash()), equalTo(new HashedBytesRef(four())));
assertThat(hashedBytesValuesIter.hasNext(), equalTo(false));
StringValues stringValues = fieldData.getStringValues();
assertThat(stringValues.hasValue(0), equalTo(true));
assertThat(stringValues.hasValue(1), equalTo(true));
assertThat(stringValues.hasValue(2), equalTo(true));
assertThat(stringValues.getValue(0), equalTo(two()));
assertThat(stringValues.getValue(1), equalTo(one()));
assertThat(stringValues.getValue(2), equalTo(three()));
StringValues.Iter stringValuesIter = stringValues.getIter(0);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(two()));
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(four()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(1);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(one()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(2);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(three()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValues.forEachValueInDoc(0, new StringValuesVerifierProc(0).addExpected(two()).addExpected(four()));
stringValues.forEachValueInDoc(1, new StringValuesVerifierProc(1).addExpected(one()));
stringValues.forEachValueInDoc(2, new StringValuesVerifierProc(2).addExpected(three()));
IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(writer, true));
TopFieldDocs topDocs = searcher.search(new MatchAllDocsQuery(), 10, new Sort(new SortField("value", indexFieldData.comparatorSource(null, SortMode.MIN))));
assertThat(topDocs.totalHits, equalTo(3));
@ -486,35 +403,6 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
hashedBytesValuesIter = hashedBytesValues.getIter(1);
assertThat(hashedBytesValuesIter.hasNext(), equalTo(false));
StringValues stringValues = fieldData.getStringValues();
assertThat(stringValues.hasValue(0), equalTo(true));
assertThat(stringValues.hasValue(1), equalTo(false));
assertThat(stringValues.hasValue(2), equalTo(true));
assertThat(stringValues.getValue(0), equalTo(two()));
assertThat(stringValues.getValue(1), nullValue());
assertThat(stringValues.getValue(2), equalTo(three()));
StringValues.Iter stringValuesIter = stringValues.getIter(0);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(two()));
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(four()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(1);
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(2);
assertThat(stringValuesIter.hasNext(), equalTo(true));
assertThat(stringValuesIter.next(), equalTo(three()));
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValues.forEachValueInDoc(0, new StringValuesVerifierProc(0).addExpected(two()).addExpected(four()));
stringValues.forEachValueInDoc(1, new StringValuesVerifierProc(1).addMissing());
stringValues.forEachValueInDoc(2, new StringValuesVerifierProc(2).addExpected(three()));
}
public void testMissingValueForAll() throws Exception {
@ -571,29 +459,6 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
hashedBytesValuesIter = hashedBytesValues.getIter(2);
assertThat(hashedBytesValuesIter.hasNext(), equalTo(false));
StringValues stringValues = fieldData.getStringValues();
assertThat(stringValues.hasValue(0), equalTo(false));
assertThat(stringValues.hasValue(1), equalTo(false));
assertThat(stringValues.hasValue(2), equalTo(false));
assertThat(stringValues.getValue(0), nullValue());
assertThat(stringValues.getValue(1), nullValue());
assertThat(stringValues.getValue(2), nullValue());
StringValues.Iter stringValuesIter = stringValues.getIter(0);
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(1);
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(2);
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValues.forEachValueInDoc(0, new StringValuesVerifierProc(0).addMissing());
stringValues.forEachValueInDoc(1, new StringValuesVerifierProc(1).addMissing());
stringValues.forEachValueInDoc(2, new StringValuesVerifierProc(2).addMissing());
}
protected void fillAllMissing() throws Exception {