Refine search
/** Return the cumulated number of points across all leaves of the given * {@link IndexReader}. Leaves that do not have points for the given field * are ignored. * @see PointValues#size() */ public static long size(IndexReader reader, String field) throws IOException { long size = 0; for (LeafReaderContext ctx : reader.leaves()) { PointValues values = ctx.reader().getPointValues(field); if (values != null) { size += values.size(); } } return size; }
/** Return the cumulated number of docs that have points across all leaves * of the given {@link IndexReader}. Leaves that do not have points for the * given field are ignored. * @see PointValues#getDocCount() */ public static int getDocCount(IndexReader reader, String field) throws IOException { int count = 0; for (LeafReaderContext ctx : reader.leaves()) { PointValues values = ctx.reader().getPointValues(field); if (values != null) { count += values.getDocCount(); } } return count; }
/** This method may return null if the field does not exist or if it has no terms. */ public static Terms getTerms(IndexReader r, String field) throws IOException { final List<LeafReaderContext> leaves = r.leaves(); if (leaves.size() == 1) { return leaves.get(0).reader().terms(field); } final List<Terms> termsPerLeaf = new ArrayList<>(leaves.size()); final List<ReaderSlice> slicePerLeaf = new ArrayList<>(leaves.size()); for (int leafIdx = 0; leafIdx < leaves.size(); leafIdx++) { LeafReaderContext ctx = leaves.get(leafIdx); Terms subTerms = ctx.reader().terms(field); if (subTerms != null) { termsPerLeaf.add(subTerms); slicePerLeaf.add(new ReaderSlice(ctx.docBase, r.maxDoc(), leafIdx - 1)); } } if (termsPerLeaf.size() == 0) { return null; } else { return new MultiTerms(termsPerLeaf.toArray(Terms.EMPTY_ARRAY), slicePerLeaf.toArray(ReaderSlice.EMPTY_ARRAY)); } }
final List<LeafReaderContext> leaves = reader.leaves(); switch (leaves.size()) { case 1: return new LeafReaderFields(leaves.get(0).reader()); default: final List<Fields> fields = new ArrayList<>(leaves.size()); final List<ReaderSlice> slices = new ArrayList<>(leaves.size()); for (final LeafReaderContext ctx : leaves) { final LeafReader r = ctx.reader(); final Fields f = new LeafReaderFields(r); fields.add(f);
/** Call this to get the (merged) FieldInfos for a * composite reader. * <p> * NOTE: the returned field numbers will likely not * correspond to the actual field numbers in the underlying * readers, and codec metadata ({@link FieldInfo#getAttribute(String)} * will be unavailable. */ public static FieldInfos getMergedFieldInfos(IndexReader reader) { final String softDeletesField = reader.leaves().stream() .map(l -> l.reader().getFieldInfos().getSoftDeletesField()) .filter(Objects::nonNull).findAny().orElse(null); final FieldInfos.Builder builder = new FieldInfos.Builder(new FieldInfos.FieldNumbers(softDeletesField)); for(final LeafReaderContext ctx : reader.leaves()) { builder.add(ctx.reader().getFieldInfos()); } return builder.finish(); }
final List<LeafReaderContext> leaves = r.leaves(); final int size = leaves.size(); if (size == 0) { return null; } else if (size == 1) { return leaves.get(0).reader().getNumericDocValues(field); FieldInfo fieldInfo = leaf.reader().getFieldInfos().fieldInfo(field); if (fieldInfo != null) { DocValuesType dvType = fieldInfo.getDocValuesType();
final List<LeafReaderContext> leaves = r.leaves(); final int size = leaves.size(); if (size == 0) { return null; } else if (size == 1) { return leaves.get(0).reader().getBinaryDocValues(field); FieldInfo fieldInfo = leaf.reader().getFieldInfos().fieldInfo(field); if (fieldInfo != null) { DocValuesType dvType = fieldInfo.getDocValuesType();
/** Return the minimum packed values across all leaves of the given * {@link IndexReader}. Leaves that do not have points for the given field * are ignored. * @see PointValues#getMinPackedValue() */ public static byte[] getMinPackedValue(IndexReader reader, String field) throws IOException { byte[] minValue = null; for (LeafReaderContext ctx : reader.leaves()) { PointValues values = ctx.reader().getPointValues(field); if (values == null) { continue; } byte[] leafMinValue = values.getMinPackedValue(); if (leafMinValue == null) { continue; } if (minValue == null) { minValue = leafMinValue.clone(); } else { final int numDimensions = values.getNumIndexDimensions(); final int numBytesPerDimension = values.getBytesPerDimension(); for (int i = 0; i < numDimensions; ++i) { int offset = i * numBytesPerDimension; if (FutureArrays.compareUnsigned(leafMinValue, offset, offset + numBytesPerDimension, minValue, offset, offset + numBytesPerDimension) < 0) { System.arraycopy(leafMinValue, offset, minValue, offset, numBytesPerDimension); } } } } return minValue; }
/** Return the maximum packed values across all leaves of the given * {@link IndexReader}. Leaves that do not have points for the given field * are ignored. * @see PointValues#getMaxPackedValue() */ public static byte[] getMaxPackedValue(IndexReader reader, String field) throws IOException { byte[] maxValue = null; for (LeafReaderContext ctx : reader.leaves()) { PointValues values = ctx.reader().getPointValues(field); if (values == null) { continue; } byte[] leafMaxValue = values.getMaxPackedValue(); if (leafMaxValue == null) { continue; } if (maxValue == null) { maxValue = leafMaxValue.clone(); } else { final int numDimensions = values.getNumIndexDimensions(); final int numBytesPerDimension = values.getBytesPerDimension(); for (int i = 0; i < numDimensions; ++i) { int offset = i * numBytesPerDimension; if (FutureArrays.compareUnsigned(leafMaxValue, offset, offset + numBytesPerDimension, maxValue, offset, offset + numBytesPerDimension) > 0) { System.arraycopy(leafMaxValue, offset, maxValue, offset, numBytesPerDimension); } } } } return maxValue; }
final List<LeafReaderContext> leaves = r.leaves(); final int size = leaves.size(); if (size == 0) { return null; } else if (size == 1) { return leaves.get(0).reader().getSortedNumericDocValues(field); for (int i = 0; i < size; i++) { LeafReaderContext context = leaves.get(i); SortedNumericDocValues v = context.reader().getSortedNumericDocValues(field); if (v == null) { v = DocValues.emptySortedNumeric(context.reader().maxDoc()); } else { anyReal = true;
final List<LeafReaderContext> leaves = r.leaves(); final int size = leaves.size(); return null; } else if (size == 1) { return leaves.get(0).reader().getSortedDocValues(field); for (int i = 0; i < size; i++) { LeafReaderContext context = leaves.get(i); SortedDocValues v = context.reader().getSortedDocValues(field); if (v == null) { v = DocValues.emptySorted();
final List<LeafReaderContext> leaves = r.leaves(); final int size = leaves.size(); return null; } else if (size == 1) { return leaves.get(0).reader().getSortedSetDocValues(field); for (int i = 0; i < size; i++) { LeafReaderContext context = leaves.get(i); SortedSetDocValues v = context.reader().getSortedSetDocValues(field); if (v == null) { v = DocValues.emptySortedSet();