parent
10201d511c
commit
76511158b5
|
@ -75,6 +75,8 @@ public class MultiOrdinals extends Ordinals {
|
|||
}
|
||||
lastEndOffset = endOffset;
|
||||
}
|
||||
endOffsets.freeze();
|
||||
ords.freeze();
|
||||
assert endOffsets.size() == builder.maxDoc();
|
||||
assert ords.size() == builder.getTotalNumOrds() : ords.size() + " != " + builder.getTotalNumOrds();
|
||||
}
|
||||
|
@ -109,8 +111,9 @@ public class MultiOrdinals extends Ordinals {
|
|||
|
||||
@Override
|
||||
public int getOrd(int docId) {
|
||||
final long offset = docId != 0 ? endOffsets.get(docId - 1) : 0;
|
||||
return (int) ords.get(offset);
|
||||
final long startOffset = docId != 0 ? endOffsets.get(docId - 1) : 0;
|
||||
final long endOffset = endOffsets.get(docId);
|
||||
return startOffset == endOffset ? -1 : (int) ords.get(startOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,6 +40,11 @@ import java.util.Comparator;
|
|||
*/
|
||||
public final class OrdinalsBuilder implements Closeable {
|
||||
|
||||
/**
|
||||
* Whether to for the use of {@link MultiOrdinals} to store the ordinals for testing purposes.
|
||||
*/
|
||||
public static final String FORCE_MULTI_ORDINALS = "force_multi_ordinals";
|
||||
|
||||
/**
|
||||
* Default acceptable overhead ratio. {@link OrdinalsBuilder} memory usage is mostly transient so it is likely a better trade-off to
|
||||
* trade memory for speed in order to resize less often.
|
||||
|
@ -395,7 +400,8 @@ public final class OrdinalsBuilder implements Closeable {
|
|||
*/
|
||||
public Ordinals build(Settings settings) {
|
||||
final float acceptableOverheadRatio = settings.getAsFloat("acceptable_overhead_ratio", PackedInts.FASTEST);
|
||||
if (numMultiValuedDocs > 0 || MultiOrdinals.significantlySmallerThanSinglePackedOrdinals(maxDoc, numDocsWithValue, getValueCount(), acceptableOverheadRatio)) {
|
||||
final boolean forceMultiOrdinals = settings.getAsBoolean(FORCE_MULTI_ORDINALS, false);
|
||||
if (forceMultiOrdinals || numMultiValuedDocs > 0 || MultiOrdinals.significantlySmallerThanSinglePackedOrdinals(maxDoc, numDocsWithValue, getValueCount(), acceptableOverheadRatio)) {
|
||||
// MultiOrdinals can be smaller than SinglePackedOrdinals for sparse fields
|
||||
return new MultiOrdinals(this, acceptableOverheadRatio);
|
||||
} else {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.fielddata;
|
||||
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -27,6 +28,6 @@ public class FSTPackedBytesStringFieldDataTests extends AbstractStringFieldDataT
|
|||
|
||||
@Override
|
||||
protected FieldDataType getFieldDataType() {
|
||||
return new FieldDataType("string", ImmutableSettings.builder().put("format", "fst"));
|
||||
return new FieldDataType("string", ImmutableSettings.builder().put("format", "fst").put(OrdinalsBuilder.FORCE_MULTI_ORDINALS, randomBoolean()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.fielddata;
|
||||
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -27,6 +28,6 @@ public class PagedBytesStringFieldDataTests extends AbstractStringFieldDataTests
|
|||
|
||||
@Override
|
||||
protected FieldDataType getFieldDataType() {
|
||||
return new FieldDataType("string", ImmutableSettings.builder().put("format", "paged_bytes"));
|
||||
return new FieldDataType("string", ImmutableSettings.builder().put("format", "paged_bytes").put(OrdinalsBuilder.FORCE_MULTI_ORDINALS, randomBoolean()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue