Internal: Avoid unnecessary utf8 conversion when creating ScriptDocValues for a string field.

This regression was introduced in #6908: the conversion from RandomAccessOrds
to SortedBinaryDocValues goes through Strings while both impls actually work
on BytesRef, so the SortedBinaryDocValues instance could directly return the
BytesRefs returned by the RandomAccessOrds.

Close #9306
This commit is contained in:
Adrien Grand 2015-02-04 09:50:04 +01:00
parent 74c7b5a197
commit 8b76cd76f9
1 changed files with 16 additions and 9 deletions

View File

@ -383,19 +383,26 @@ public enum FieldData {
/** /**
* Return a {@link String} representation of the provided values. That is * Return a {@link String} representation of the provided values. That is
* typically used for scripts or for the `map` execution mode of terms aggs. * typically used for scripts or for the `map` execution mode of terms aggs.
* NOTE: this is very slow! * NOTE: this is slow!
*/ */
public static SortedBinaryDocValues toString(final RandomAccessOrds values) { public static SortedBinaryDocValues toString(final RandomAccessOrds values) {
return toString(new ToStringValues() { return new SortedBinaryDocValues() {
@Override @Override
public void get(int docID, List<CharSequence> list) { public BytesRef valueAt(int index) {
values.setDocument(docID); return values.lookupOrd(values.ordAt(index));
for (int i = 0, count = values.cardinality(); i < count; ++i) {
final long ord = values.ordAt(i);
list.add(values.lookupOrd(ord).utf8ToString());
} }
@Override
public void setDocument(int docId) {
values.setDocument(docId);
} }
});
@Override
public int count() {
return values.cardinality();
}
};
} }
/** /**