Java Code Examples for org.apache.lucene.index.DocValues#getSortedNumeric()

The following examples show how to use org.apache.lucene.index.DocValues#getSortedNumeric() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToParentBlockJoinSortField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private FieldComparator<?> getFloatComparator(int numHits) {
  return new FieldComparator.FloatComparator(numHits, getField(), (Float) missingValue) {
    @Override
    protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
      SortedNumericDocValues sortedNumeric = DocValues.getSortedNumeric(context.reader(), field);
      final BlockJoinSelector.Type type = order
          ? BlockJoinSelector.Type.MAX
          : BlockJoinSelector.Type.MIN;
      final BitSet parents = parentFilter.getBitSet(context);
      final BitSet children = childFilter.getBitSet(context);
      if (children == null) {
        return DocValues.emptyNumeric();
      }
      return new FilterNumericDocValues(BlockJoinSelector.wrap(sortedNumeric, type, parents, toIter(children))) {
        @Override
        public long longValue() throws IOException {
          // undo the numericutils sortability
          return NumericUtils.sortableFloatBits((int) super.longValue());
        }
      };
    }
  };
}
 
Example 2
Source File: TestPrefixCompletionQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Bits getBits(final LeafReaderContext context) throws IOException {
  final int maxDoc = context.reader().maxDoc();
  FixedBitSet bits = new FixedBitSet(maxDoc);
  final SortedNumericDocValues values = DocValues.getSortedNumeric(context.reader(), field);
  int docID;
  while ((docID = values.nextDoc()) != NO_MORE_DOCS) {
    final int count = values.docValueCount();
    for (int i = 0; i < count; ++i) {
      final long v = values.nextValue();
      if (v >= min && v <= max) {
        bits.set(docID);
        break;
      }
    }
  }
  return bits;
}
 
Example 3
Source File: SortedNumericDVIndexFieldData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public SortedNumericDocValues getLongValues() {
    try {
        return DocValues.getSortedNumeric(reader, field);
    } catch (IOException e) {
        throw new IllegalStateException("Cannot load doc values", e);
    }
}
 
Example 4
Source File: LatLonPointDistanceComparator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
  LeafReader reader = context.reader();
  FieldInfo info = reader.getFieldInfos().fieldInfo(field);
  if (info != null) {
    LatLonDocValuesField.checkCompatible(info);
  }
  currentDocs = DocValues.getSortedNumeric(reader, field);
  valuesDocID = -1;
  return this;
}
 
Example 5
Source File: XYPointDistanceComparator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
  LeafReader reader = context.reader();
  FieldInfo info = reader.getFieldInfos().fieldInfo(field);
  if (info != null) {
    XYDocValuesField.checkCompatible(info);
  }
  currentDocs = DocValues.getSortedNumeric(reader, field);
  valuesDocID = -1;
  return this;
}
 
Example 6
Source File: Geo3DPointDistanceComparator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
  LeafReader reader = context.reader();
  FieldInfo info = reader.getFieldInfos().fieldInfo(field);
  if (info != null) {
    Geo3DDocValuesField.checkCompatible(info);
  }
  currentDocs = DocValues.getSortedNumeric(reader, field);
  return this;
}
 
Example 7
Source File: SortedNumericDVIndexFieldData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public SortedNumericDoubleValues getDoubleValues() {
    try {
        SortedNumericDocValues raw = DocValues.getSortedNumeric(reader, field);

        NumericDocValues single = DocValues.unwrapSingleton(raw);
        if (single != null) {
            return FieldData.singleton(new SingleFloatValues(single), DocValues.unwrapSingletonBits(raw));
        } else {
            return new MultiFloatValues(raw);
        }
    } catch (IOException e) {
        throw new IllegalStateException("Cannot load doc values", e);
    }
}
 
Example 8
Source File: AbstractGeoPointDVIndexFieldData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public AtomicGeoPointFieldData load(LeafReaderContext context) {
    try {
        if (indexCreatedBefore2x) {
            return new GeoPointLegacyDVAtomicFieldData(DocValues.getBinary(context.reader(), fieldNames.indexName()));
        }
        return new GeoPointDVAtomicFieldData(DocValues.getSortedNumeric(context.reader(), fieldNames.indexName()));
    } catch (IOException e) {
        throw new IllegalStateException("Cannot load doc values", e);
    }
}
 
Example 9
Source File: SumAggregation.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void loadDocValues(LeafReader reader) throws IOException {
    values = DocValues.getSortedNumeric(reader, columnName);
}
 
Example 10
Source File: MultiValuedIntFieldSource.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
protected NumericDocValues getNumericDocValues(Map<Object, Object> context, LeafReaderContext readerContext) throws IOException {
  SortedNumericDocValues sortedDv = DocValues.getSortedNumeric(readerContext.reader(), field);
  return SortedNumericSelector.wrap(sortedDv, selector, SortField.Type.INT);
}
 
Example 11
Source File: FloatMultiPointField.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void doSetNextReader(LeafReaderContext context) throws IOException {
  docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
}
 
Example 12
Source File: LongMultiPointField.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void doSetNextReader(LeafReaderContext context) throws IOException {
  docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
}
 
Example 13
Source File: PercentileAgg.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void setNextReader(LeafReaderContext readerContext) throws IOException {
  super.setNextReader(readerContext);
  values = DocValues.getSortedNumeric(readerContext.reader(),  sf.getName());
}
 
Example 14
Source File: HLLAgg.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void setNextReader(LeafReaderContext readerContext) throws IOException {
  super.setNextReader(readerContext);
  values = DocValues.getSortedNumeric(readerContext.reader(),  sf.getName());
}
 
Example 15
Source File: GeoPointColumnReference.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void setNextReader(LeafReaderContext context) throws IOException {
    super.setNextReader(context);
    values = DocValues.getSortedNumeric(context.reader(), columnName);
}
 
Example 16
Source File: SumAggregation.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void loadDocValues(LeafReader reader) throws IOException {
    values = DocValues.getSortedNumeric(reader, columnName);
}
 
Example 17
Source File: IntegerColumnReference.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void setNextReader(LeafReaderContext context) throws IOException {
    super.setNextReader(context);
    values = DocValues.getSortedNumeric(context.reader(), columnName);
}
 
Example 18
Source File: AverageAggregation.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void loadDocValues(LeafReader reader) throws IOException {
    values = DocValues.getSortedNumeric(reader, columnName);
}
 
Example 19
Source File: AverageAggregation.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void loadDocValues(LeafReader reader) throws IOException {
    values = DocValues.getSortedNumeric(reader, columnName);

}
 
Example 20
Source File: TestLucene80DocValuesFormat.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void doTestSortedNumericBlocksOfVariousBitsPerValue(LongSupplier counts) throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
  conf.setMaxBufferedDocs(atLeast(Lucene80DocValuesFormat.NUMERIC_BLOCK_SIZE));
  conf.setRAMBufferSizeMB(-1);
  conf.setMergePolicy(newLogMergePolicy(random().nextBoolean()));
  IndexWriter writer = new IndexWriter(dir, conf);
  
  final int numDocs = atLeast(Lucene80DocValuesFormat.NUMERIC_BLOCK_SIZE*3);
  final LongSupplier values = blocksOfVariousBPV();
  for (int i = 0; i < numDocs; i++) {
    Document doc = new Document();
    
    int valueCount = (int) counts.getAsLong();
    long valueArray[] = new long[valueCount];
    for (int j = 0; j < valueCount; j++) {
      long value = values.getAsLong();
      valueArray[j] = value;
      doc.add(new SortedNumericDocValuesField("dv", value));
    }
    Arrays.sort(valueArray);
    for (int j = 0; j < valueCount; j++) {
      doc.add(new StoredField("stored", Long.toString(valueArray[j])));
    }
    writer.addDocument(doc);
    if (random().nextInt(31) == 0) {
      writer.commit();
    }
  }
  writer.forceMerge(1);

  writer.close();
  
  // compare
  DirectoryReader ir = DirectoryReader.open(dir);
  TestUtil.checkReader(ir);
  for (LeafReaderContext context : ir.leaves()) {
    LeafReader r = context.reader();
    SortedNumericDocValues docValues = DocValues.getSortedNumeric(r, "dv");
    for (int i = 0; i < r.maxDoc(); i++) {
      if (i > docValues.docID()) {
        docValues.nextDoc();
      }
      String expected[] = r.document(i).getValues("stored");
      if (i < docValues.docID()) {
        assertEquals(0, expected.length);
      } else {
        String actual[] = new String[docValues.docValueCount()];
        for (int j = 0; j < actual.length; j++) {
          actual[j] = Long.toString(docValues.nextValue());
        }
        assertArrayEquals(expected, actual);
      }
    }
  }
  ir.close();
  dir.close();
}