cleanup ordinals in field data

This commit is contained in:
Shay Banon 2013-01-24 22:29:56 +01:00
parent 990acff4f7
commit 45ed9ddba7
18 changed files with 293 additions and 404 deletions

View File

@ -64,4 +64,21 @@ public interface AtomicFieldData<Script extends ScriptDocValues> {
*/
Script getScriptValues();
interface WithOrdinals<Script extends ScriptDocValues> extends AtomicFieldData<Script> {
/**
* Use a non thread safe (lightweight) view of the values as bytes.
*/
BytesValues.WithOrdinals getBytesValues();
/**
* Use a non thread safe (lightweight) view of the values as bytes.
*/
HashedBytesValues.WithOrdinals getHashedBytesValues();
/**
* Use a non thread safe (lightweight) view of the values as strings.
*/
StringValues.WithOrdinals getStringValues();
}
}

View File

@ -1,41 +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;
/**
*/
public interface AtomicOrdinalFieldData<Script extends ScriptDocValues> extends AtomicFieldData<Script> {
/**
* Use a non thread safe (lightweight) view of the values as bytes.
*/
OrdinalsBytesValues getBytesValues();
/**
* Use a non thread safe (lightweight) view of the values as bytes.
*/
OrdinalsHashedBytesValues getHashedBytesValues();
/**
* Use a non thread safe (lightweight) view of the values as strings.
*/
OrdinalsStringValues getStringValues();
}

View File

@ -21,6 +21,8 @@ package org.elasticsearch.index.fielddata;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
import org.elasticsearch.index.fielddata.util.StringArrayRef;
@ -286,4 +288,85 @@ public interface BytesValues {
}
}
}
/**
* Bytes values that are based on ordinals.
*/
static interface WithOrdinals extends BytesValues {
Ordinals.Docs ordinals();
BytesRef getValueByOrd(int ord);
/**
* Returns the bytes value for the docId, with the provided "ret" which will be filled with the
* result which will also be returned. If there is no value for this docId, the length will be 0.
* Note, the bytes are not "safe".
*/
BytesRef getValueScratchByOrd(int ord, BytesRef ret);
BytesRef getSafeValueByOrd(int ord);
public static class Empty extends BytesValues.Empty implements WithOrdinals {
private final Ordinals ordinals;
public Empty(EmptyOrdinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public BytesRef getValueByOrd(int ord) {
return null;
}
@Override
public BytesRef getValueScratchByOrd(int ord, BytesRef ret) {
ret.length = 0;
return ret;
}
@Override
public BytesRef getSafeValueByOrd(int ord) {
return null;
}
}
public static class StringBased extends BytesValues.StringBased implements WithOrdinals {
private final StringValues.WithOrdinals values;
public StringBased(StringValues.WithOrdinals values) {
super(values);
this.values = values;
}
@Override
public Ordinals.Docs ordinals() {
return values.ordinals();
}
@Override
public BytesRef getValueByOrd(int ord) {
scratch.copyChars(values.getValueByOrd(ord));
return scratch;
}
@Override
public BytesRef getValueScratchByOrd(int ord, BytesRef ret) {
ret.copyChars(values.getValueByOrd(ord));
return ret;
}
@Override
public BytesRef getSafeValueByOrd(int ord) {
return new BytesRef(values.getValueByOrd(ord));
}
}
}
}

View File

@ -22,6 +22,8 @@ package org.elasticsearch.index.fielddata;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
*/
@ -330,4 +332,90 @@ public interface HashedBytesValues {
}
}
}
public interface WithOrdinals extends HashedBytesValues {
Ordinals.Docs ordinals();
HashedBytesRef getValueByOrd(int ord);
HashedBytesRef getSafeValueByOrd(int ord);
public static class Empty extends HashedBytesValues.Empty implements WithOrdinals {
private final Ordinals ordinals;
public Empty(EmptyOrdinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public HashedBytesRef getValueByOrd(int ord) {
return null;
}
@Override
public HashedBytesRef getSafeValueByOrd(int ord) {
return null;
}
}
static class BytesBased extends HashedBytesValues.BytesBased implements WithOrdinals {
private final BytesValues.WithOrdinals values;
public BytesBased(BytesValues.WithOrdinals values) {
super(values);
this.values = values;
}
@Override
public Ordinals.Docs ordinals() {
return values.ordinals();
}
@Override
public HashedBytesRef getValueByOrd(int ord) {
scratch.bytes = values.getValueByOrd(ord);
return scratch.resetHashCode();
}
@Override
public HashedBytesRef getSafeValueByOrd(int ord) {
return new HashedBytesRef(values.getSafeValueByOrd(ord));
}
}
static class StringBased extends HashedBytesValues.StringBased implements WithOrdinals {
private final StringValues.WithOrdinals values;
public StringBased(StringValues.WithOrdinals values) {
super(values);
this.values = values;
}
@Override
public Ordinals.Docs ordinals() {
return values.ordinals();
}
@Override
public HashedBytesRef getValueByOrd(int ord) {
scratch.bytes.copyChars(values.getValueByOrd(ord));
return scratch.resetHashCode();
}
@Override
public HashedBytesRef getSafeValueByOrd(int ord) {
return new HashedBytesRef(new BytesRef(values.getValueByOrd(ord)));
}
}
}
}

View File

@ -78,4 +78,18 @@ public interface IndexFieldData<FD extends AtomicFieldData> extends IndexCompone
IndexFieldData build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache);
}
public interface WithOrdinals<FD extends AtomicFieldData.WithOrdinals> extends IndexFieldData<FD> {
/**
* Loads the atomic field data for the reader, possibly cached.
*/
FD load(AtomicReaderContext context);
/**
* Loads directly the atomic field data for the reader, ignoring any caching involved.
*/
FD loadDirect(AtomicReaderContext context) throws Exception;
}
}

View File

@ -1,37 +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.index.AtomicReaderContext;
/**
*/
public interface IndexOrdinalFieldData<FD extends AtomicOrdinalFieldData> extends IndexFieldData<FD> {
/**
* Loads the atomic field data for the reader, possibly cached.
*/
FD load(AtomicReaderContext context);
/**
* Loads directly the atomic field data for the reader, ignoring any caching involved.
*/
FD loadDirect(AtomicReaderContext context) throws Exception;
}

View File

@ -1,104 +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.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
*/
public interface OrdinalsBytesValues extends BytesValues {
Ordinals.Docs ordinals();
BytesRef getValueByOrd(int ord);
/**
* Returns the bytes value for the docId, with the provided "ret" which will be filled with the
* result which will also be returned. If there is no value for this docId, the length will be 0.
* Note, the bytes are not "safe".
*/
BytesRef getValueScratchByOrd(int ord, BytesRef ret);
BytesRef getSafeValueByOrd(int ord);
public static class Empty extends BytesValues.Empty implements OrdinalsBytesValues {
private final Ordinals ordinals;
public Empty(EmptyOrdinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public BytesRef getValueByOrd(int ord) {
return null;
}
@Override
public BytesRef getValueScratchByOrd(int ord, BytesRef ret) {
ret.length = 0;
return ret;
}
@Override
public BytesRef getSafeValueByOrd(int ord) {
return null;
}
}
public static class StringBased extends BytesValues.StringBased implements OrdinalsBytesValues {
private final OrdinalsStringValues values;
public StringBased(OrdinalsStringValues values) {
super(values);
this.values = values;
}
@Override
public Ordinals.Docs ordinals() {
return values.ordinals();
}
@Override
public BytesRef getValueByOrd(int ord) {
scratch.copyChars(values.getValueByOrd(ord));
return scratch;
}
@Override
public BytesRef getValueScratchByOrd(int ord, BytesRef ret) {
ret.copyChars(values.getValueByOrd(ord));
return ret;
}
@Override
public BytesRef getSafeValueByOrd(int ord) {
return new BytesRef(values.getValueByOrd(ord));
}
}
}

View File

@ -1,112 +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.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
*/
public interface OrdinalsHashedBytesValues extends HashedBytesValues {
Ordinals.Docs ordinals();
HashedBytesRef getValueByOrd(int ord);
HashedBytesRef getSafeValueByOrd(int ord);
public static class Empty extends HashedBytesValues.Empty implements OrdinalsHashedBytesValues {
private final Ordinals ordinals;
public Empty(EmptyOrdinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public HashedBytesRef getValueByOrd(int ord) {
return null;
}
@Override
public HashedBytesRef getSafeValueByOrd(int ord) {
return null;
}
}
static class BytesBased extends HashedBytesValues.BytesBased implements OrdinalsHashedBytesValues {
private final OrdinalsBytesValues values;
public BytesBased(OrdinalsBytesValues values) {
super(values);
this.values = values;
}
@Override
public Ordinals.Docs ordinals() {
return values.ordinals();
}
@Override
public HashedBytesRef getValueByOrd(int ord) {
scratch.bytes = values.getValueByOrd(ord);
return scratch.resetHashCode();
}
@Override
public HashedBytesRef getSafeValueByOrd(int ord) {
return new HashedBytesRef(values.getSafeValueByOrd(ord));
}
}
static class StringBased extends HashedBytesValues.StringBased implements OrdinalsHashedBytesValues {
private final OrdinalsStringValues values;
public StringBased(OrdinalsStringValues values) {
super(values);
this.values = values;
}
@Override
public Ordinals.Docs ordinals() {
return values.ordinals();
}
@Override
public HashedBytesRef getValueByOrd(int ord) {
scratch.bytes.copyChars(values.getValueByOrd(ord));
return scratch.resetHashCode();
}
@Override
public HashedBytesRef getSafeValueByOrd(int ord) {
return new HashedBytesRef(new BytesRef(values.getValueByOrd(ord)));
}
}
}

View File

@ -1,51 +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.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
*/
public interface OrdinalsStringValues extends StringValues {
Ordinals.Docs ordinals();
String getValueByOrd(int ord);
public static class Empty extends StringValues.Empty implements OrdinalsStringValues {
private final Ordinals ordinals;
public Empty(EmptyOrdinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public String getValueByOrd(int ord) {
return null;
}
}
}

View File

@ -20,6 +20,8 @@
package org.elasticsearch.index.fielddata;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.*;
/**
@ -604,4 +606,29 @@ public interface StringValues {
}
}
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(EmptyOrdinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public String getValueByOrd(int ord) {
return null;
}
}
}
}

View File

@ -22,7 +22,6 @@ package org.elasticsearch.index.fielddata.fieldcomparator;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.SortField;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexOrdinalFieldData;
import java.io.IOException;
@ -44,8 +43,8 @@ public class BytesRefFieldComparatorSource extends IndexFieldData.XFieldComparat
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
if (indexFieldData.valuesOrdered() && indexFieldData instanceof IndexOrdinalFieldData) {
return new BytesRefOrdValComparator((IndexOrdinalFieldData) indexFieldData, numHits);
if (indexFieldData.valuesOrdered() && indexFieldData instanceof IndexFieldData.WithOrdinals) {
return new BytesRefOrdValComparator((IndexFieldData.WithOrdinals) indexFieldData, numHits);
}
return new BytesRefValComparator(indexFieldData, numHits);
}

View File

@ -23,9 +23,8 @@ import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexOrdinalFieldData;
import org.elasticsearch.index.fielddata.OrdinalsBytesValues;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import java.io.IOException;
@ -43,7 +42,7 @@ import java.io.IOException;
*/
public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
final IndexOrdinalFieldData indexFieldData;
final IndexFieldData.WithOrdinals indexFieldData;
/* Ords for each slot.
@lucene.internal */
@ -66,7 +65,7 @@ public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
/* Current reader's doc ord/values.
@lucene.internal */
OrdinalsBytesValues termsIndex;
BytesValues.WithOrdinals termsIndex;
/* Bottom slot, or -1 if queue isn't full yet
@lucene.internal */
@ -89,7 +88,7 @@ public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
final BytesRef tempBR = new BytesRef();
public BytesRefOrdValComparator(IndexOrdinalFieldData indexFieldData, int numHits) {
public BytesRefOrdValComparator(IndexFieldData.WithOrdinals indexFieldData, int numHits) {
this.indexFieldData = indexFieldData;
ords = new int[numHits];
values = new BytesRef[numHits];
@ -191,10 +190,10 @@ public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
// Used per-segment when bit width of doc->ord is 8:
private final class ByteOrdComparator extends PerSegmentComparator {
private final byte[] readerOrds;
private final OrdinalsBytesValues termsIndex;
private final BytesValues.WithOrdinals termsIndex;
private final int docBase;
public ByteOrdComparator(byte[] readerOrds, OrdinalsBytesValues termsIndex, int docBase) {
public ByteOrdComparator(byte[] readerOrds, BytesValues.WithOrdinals termsIndex, int docBase) {
this.readerOrds = readerOrds;
this.termsIndex = termsIndex;
this.docBase = docBase;
@ -237,10 +236,10 @@ public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
// Used per-segment when bit width of doc->ord is 16:
private final class ShortOrdComparator extends PerSegmentComparator {
private final short[] readerOrds;
private final OrdinalsBytesValues termsIndex;
private final BytesValues.WithOrdinals termsIndex;
private final int docBase;
public ShortOrdComparator(short[] readerOrds, OrdinalsBytesValues termsIndex, int docBase) {
public ShortOrdComparator(short[] readerOrds, BytesValues.WithOrdinals termsIndex, int docBase) {
this.readerOrds = readerOrds;
this.termsIndex = termsIndex;
this.docBase = docBase;
@ -283,10 +282,10 @@ public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
// Used per-segment when bit width of doc->ord is 32:
private final class IntOrdComparator extends PerSegmentComparator {
private final int[] readerOrds;
private final OrdinalsBytesValues termsIndex;
private final BytesValues.WithOrdinals termsIndex;
private final int docBase;
public IntOrdComparator(int[] readerOrds, OrdinalsBytesValues termsIndex, int docBase) {
public IntOrdComparator(int[] readerOrds, BytesValues.WithOrdinals termsIndex, int docBase) {
this.readerOrds = readerOrds;
this.termsIndex = termsIndex;
this.docBase = docBase;
@ -331,10 +330,10 @@ public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
final class AnyOrdComparator extends PerSegmentComparator {
private final IndexFieldData fieldData;
private final Ordinals.Docs readerOrds;
private final OrdinalsBytesValues termsIndex;
private final BytesValues.WithOrdinals termsIndex;
private final int docBase;
public AnyOrdComparator(IndexFieldData fieldData, OrdinalsBytesValues termsIndex, int docBase) {
public AnyOrdComparator(IndexFieldData fieldData, BytesValues.WithOrdinals termsIndex, int docBase) {
this.fieldData = fieldData;
this.readerOrds = termsIndex.ordinals();
this.termsIndex = termsIndex;
@ -449,11 +448,11 @@ public final class BytesRefOrdValComparator extends FieldComparator<BytesRef> {
return values[slot];
}
final protected static int binarySearch(OrdinalsBytesValues a, BytesRef key) {
final protected static int binarySearch(BytesValues.WithOrdinals a, BytesRef key) {
return binarySearch(a, key, 1, a.ordinals().getNumDocs() - 1);
}
final protected static int binarySearch(OrdinalsBytesValues a, BytesRef key, int low, int high) {
final protected static int binarySearch(BytesValues.WithOrdinals a, BytesRef key, int low, int high) {
while (low <= high) {
int mid = (low + high) >>> 1;

View File

@ -22,7 +22,8 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.AtomicFieldData;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
@ -31,7 +32,7 @@ import org.elasticsearch.index.fielddata.util.StringArrayRef;
/**
*/
public class ConcreteBytesRefAtomicFieldData implements AtomicOrdinalFieldData<ScriptDocValues.Strings> {
public class ConcreteBytesRefAtomicFieldData implements AtomicFieldData.WithOrdinals<ScriptDocValues.Strings> {
public static ConcreteBytesRefAtomicFieldData empty(int numDocs) {
return new Empty(numDocs);
@ -81,12 +82,12 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicOrdinalFieldData<S
}
@Override
public OrdinalsBytesValues getBytesValues() {
public BytesValues.WithOrdinals getBytesValues() {
return ordinals.isMultiValued() ? new BytesValues.Multi(values, ordinals.ordinals()) : new BytesValues.Single(values, ordinals.ordinals());
}
@Override
public OrdinalsHashedBytesValues getHashedBytesValues() {
public HashedBytesValues.WithOrdinals getHashedBytesValues() {
if (hashes == null) {
int[] hashes = new int[values.length];
for (int i = 0; i < values.length; i++) {
@ -99,7 +100,7 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicOrdinalFieldData<S
}
@Override
public OrdinalsStringValues getStringValues() {
public StringValues.WithOrdinals getStringValues() {
return ordinals.isMultiValued() ? new StringValues.Multi(values, ordinals.ordinals()) : new StringValues.Single(values, ordinals.ordinals());
}
@ -108,7 +109,7 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicOrdinalFieldData<S
return new ScriptDocValues.Strings(getStringValues());
}
static abstract class BytesValues implements org.elasticsearch.index.fielddata.OrdinalsBytesValues {
static abstract class BytesValues implements org.elasticsearch.index.fielddata.BytesValues.WithOrdinals {
protected final BytesRef[] values;
protected final Ordinals.Docs ordinals;
@ -292,7 +293,7 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicOrdinalFieldData<S
}
}
static abstract class HashedBytesValues implements org.elasticsearch.index.fielddata.OrdinalsHashedBytesValues {
static abstract class HashedBytesValues implements org.elasticsearch.index.fielddata.HashedBytesValues.WithOrdinals {
protected final BytesRef[] values;
protected final int[] hashes;
@ -438,7 +439,7 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicOrdinalFieldData<S
}
}
static abstract class StringValues implements OrdinalsStringValues {
static abstract class StringValues implements org.elasticsearch.index.fielddata.StringValues.WithOrdinals {
protected final BytesRef[] values;
protected final Ordinals.Docs ordinals;
@ -619,18 +620,18 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicOrdinalFieldData<S
}
@Override
public OrdinalsBytesValues getBytesValues() {
return new OrdinalsBytesValues.Empty((EmptyOrdinals) ordinals);
public BytesValues.WithOrdinals getBytesValues() {
return new BytesValues.WithOrdinals.Empty((EmptyOrdinals) ordinals);
}
@Override
public OrdinalsHashedBytesValues getHashedBytesValues() {
return new OrdinalsHashedBytesValues.Empty((EmptyOrdinals) ordinals);
public HashedBytesValues.WithOrdinals getHashedBytesValues() {
return new HashedBytesValues.WithOrdinals.Empty((EmptyOrdinals) ordinals);
}
@Override
public OrdinalsStringValues getStringValues() {
return new OrdinalsStringValues.Empty((EmptyOrdinals) ordinals);
public StringValues.WithOrdinals getStringValues() {
return new StringValues.WithOrdinals.Empty((EmptyOrdinals) ordinals);
}
@Override

View File

@ -25,7 +25,10 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.AbstractIndexFieldData;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.SingleArrayOrdinals;
@ -36,7 +39,7 @@ import java.util.ArrayList;
/**
*/
public class ConcreteBytesRefIndexFieldData extends AbstractIndexFieldData<ConcreteBytesRefAtomicFieldData> implements IndexOrdinalFieldData<ConcreteBytesRefAtomicFieldData> {
public class ConcreteBytesRefIndexFieldData extends AbstractIndexFieldData<ConcreteBytesRefAtomicFieldData> implements IndexFieldData.WithOrdinals<ConcreteBytesRefAtomicFieldData> {
public static class Builder implements IndexFieldData.Builder {

View File

@ -25,7 +25,8 @@ import org.apache.lucene.util.packed.GrowableWriter;
import org.apache.lucene.util.packed.PackedInts;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.AtomicFieldData;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
@ -34,7 +35,7 @@ import org.elasticsearch.index.fielddata.util.StringArrayRef;
/**
*/
public class PagedBytesAtomicFieldData implements AtomicOrdinalFieldData<ScriptDocValues.Strings> {
public class PagedBytesAtomicFieldData implements AtomicFieldData.WithOrdinals<ScriptDocValues.Strings> {
public static PagedBytesAtomicFieldData empty(int numDocs) {
return new Empty(numDocs);
@ -86,12 +87,12 @@ public class PagedBytesAtomicFieldData implements AtomicOrdinalFieldData<ScriptD
}
@Override
public OrdinalsBytesValues getBytesValues() {
public BytesValues.WithOrdinals getBytesValues() {
return ordinals.isMultiValued() ? new BytesValues.Multi(bytes, termOrdToBytesOffset, ordinals.ordinals()) : new BytesValues.Single(bytes, termOrdToBytesOffset, ordinals.ordinals());
}
@Override
public OrdinalsHashedBytesValues getHashedBytesValues() {
public HashedBytesValues.WithOrdinals getHashedBytesValues() {
if (hashes == null) {
int numberOfValues = termOrdToBytesOffset.size();
int[] hashes = new int[numberOfValues];
@ -106,7 +107,7 @@ public class PagedBytesAtomicFieldData implements AtomicOrdinalFieldData<ScriptD
}
@Override
public OrdinalsStringValues getStringValues() {
public StringValues.WithOrdinals getStringValues() {
return ordinals.isMultiValued() ? new StringValues.Multi(bytes, termOrdToBytesOffset, ordinals.ordinals()) : new StringValues.Single(bytes, termOrdToBytesOffset, ordinals.ordinals());
}
@ -115,7 +116,7 @@ public class PagedBytesAtomicFieldData implements AtomicOrdinalFieldData<ScriptD
return new ScriptDocValues.Strings(getStringValues());
}
static abstract class BytesValues implements org.elasticsearch.index.fielddata.OrdinalsBytesValues {
static abstract class BytesValues implements org.elasticsearch.index.fielddata.BytesValues.WithOrdinals {
protected final PagedBytes.Reader bytes;
protected final PackedInts.Reader termOrdToBytesOffset;
@ -291,7 +292,7 @@ public class PagedBytesAtomicFieldData implements AtomicOrdinalFieldData<ScriptD
}
}
static abstract class HashedBytesValues implements org.elasticsearch.index.fielddata.OrdinalsHashedBytesValues {
static abstract class HashedBytesValues implements org.elasticsearch.index.fielddata.HashedBytesValues.WithOrdinals {
protected final PagedBytes.Reader bytes;
protected final PackedInts.Reader termOrdToBytesOffset;
@ -441,7 +442,7 @@ public class PagedBytesAtomicFieldData implements AtomicOrdinalFieldData<ScriptD
}
}
static abstract class StringValues implements OrdinalsStringValues {
static abstract class StringValues implements org.elasticsearch.index.fielddata.StringValues.WithOrdinals {
protected final PagedBytes.Reader bytes;
protected final PackedInts.Reader termOrdToBytesOffset;
@ -630,18 +631,18 @@ public class PagedBytesAtomicFieldData implements AtomicOrdinalFieldData<ScriptD
}
@Override
public OrdinalsBytesValues getBytesValues() {
return new OrdinalsBytesValues.Empty((EmptyOrdinals) ordinals);
public BytesValues.WithOrdinals getBytesValues() {
return new BytesValues.WithOrdinals.Empty((EmptyOrdinals) ordinals);
}
@Override
public OrdinalsHashedBytesValues getHashedBytesValues() {
public HashedBytesValues.WithOrdinals getHashedBytesValues() {
return new HashedBytesValues.Empty((EmptyOrdinals) ordinals);
}
@Override
public OrdinalsStringValues getStringValues() {
return new OrdinalsStringValues.Empty((EmptyOrdinals) ordinals);
public StringValues.WithOrdinals getStringValues() {
return new StringValues.WithOrdinals.Empty((EmptyOrdinals) ordinals);
}
@Override

View File

@ -29,7 +29,10 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.AbstractIndexFieldData;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.SingleArrayOrdinals;
@ -40,7 +43,7 @@ import java.util.ArrayList;
/**
*/
public class PagedBytesIndexFieldData extends AbstractIndexFieldData<PagedBytesAtomicFieldData> implements IndexOrdinalFieldData<PagedBytesAtomicFieldData> {
public class PagedBytesIndexFieldData extends AbstractIndexFieldData<PagedBytesAtomicFieldData> implements IndexFieldData.WithOrdinals<PagedBytesAtomicFieldData> {
public static class Builder implements IndexFieldData.Builder {

View File

@ -29,7 +29,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.IndexOrdinalFieldData;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.script.SearchScript;
import org.elasticsearch.search.facet.Facet;
@ -167,8 +166,8 @@ public class TermsFacetProcessor extends AbstractComponent implements FacetProce
} else {
if (script != null || "map".equals(executionHint)) {
return new TermsStringFacetCollector(facetName, indexFieldData, size, comparatorType, allTerms, context, excluded, pattern, searchScript);
} else if (indexFieldData instanceof IndexOrdinalFieldData) {
return new TermsStringOrdinalsFacetCollector(facetName, (IndexOrdinalFieldData) indexFieldData, size, comparatorType, allTerms, context, excluded, pattern);
} else if (indexFieldData instanceof IndexFieldData.WithOrdinals) {
return new TermsStringOrdinalsFacetCollector(facetName, (IndexFieldData.WithOrdinals) indexFieldData, size, comparatorType, allTerms, context, excluded, pattern);
} else {
return new TermsStringFacetCollector(facetName, indexFieldData, size, comparatorType, allTerms, context, excluded, pattern, searchScript);
}

View File

@ -25,8 +25,8 @@ import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.PriorityQueue;
import org.elasticsearch.common.CacheRecycler;
import org.elasticsearch.common.collect.BoundedTreeSet;
import org.elasticsearch.index.fielddata.IndexOrdinalFieldData;
import org.elasticsearch.index.fielddata.OrdinalsBytesValues;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.search.facet.AbstractFacetCollector;
import org.elasticsearch.search.facet.Facet;
@ -46,7 +46,7 @@ import java.util.regex.Pattern;
*/
public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
private final IndexOrdinalFieldData indexFieldData;
private final IndexFieldData.WithOrdinals indexFieldData;
private final TermsFacet.ComparatorType comparatorType;
@ -56,7 +56,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
private final int minCount;
private OrdinalsBytesValues values;
private BytesValues.WithOrdinals values;
private final List<ReaderAggregator> aggregators;
@ -69,7 +69,7 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
private final Matcher matcher;
public TermsStringOrdinalsFacetCollector(String facetName, IndexOrdinalFieldData indexFieldData, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context,
public TermsStringOrdinalsFacetCollector(String facetName, IndexFieldData.WithOrdinals indexFieldData, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context,
ImmutableSet<BytesRef> excluded, Pattern pattern) {
super(facetName);
this.indexFieldData = indexFieldData;
@ -215,14 +215,14 @@ public class TermsStringOrdinalsFacetCollector extends AbstractFacetCollector {
public static class ReaderAggregator implements Ordinals.Docs.OrdinalInDocProc {
final OrdinalsBytesValues values;
final BytesValues.WithOrdinals values;
final int[] counts;
int position = 0;
BytesRef current;
int total;
public ReaderAggregator(OrdinalsBytesValues values) {
public ReaderAggregator(BytesValues.WithOrdinals values) {
this.values = values;
this.counts = CacheRecycler.popIntArray(values.ordinals().getNumOrds());
}