Package org.apache.lucene.index

Examples of org.apache.lucene.index.NumericDocValues


    }
    int maxDoc = state.segmentInfo.getDocCount();
    final byte values[] = new byte[maxDoc];
    input.readBytes(values, 0, values.length);
    ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
    return new NumericDocValues() {
      @Override
      public long get(int docID) {
        return values[docID];
      }
    };
View Full Code Here


    final short values[] = new short[maxDoc];
    for (int i = 0; i < values.length; i++) {
      values[i] = input.readShort();
    }
    ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
    return new NumericDocValues() {
      @Override
      public long get(int docID) {
        return values[docID];
      }
    };
View Full Code Here

    final int values[] = new int[maxDoc];
    for (int i = 0; i < values.length; i++) {
      values[i] = input.readInt();
    }
    ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
    return new NumericDocValues() {
      @Override
      public long get(int docID) {
        return values[docID];
      }
    };
View Full Code Here

    final long values[] = new long[maxDoc];
    for (int i = 0; i < values.length; i++) {
      values[i] = input.readLong();
    }
    ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
    return new NumericDocValues() {
      @Override
      public long get(int docID) {
        return values[docID];
      }
    };
View Full Code Here

    final int values[] = new int[maxDoc];
    for (int i = 0; i < values.length; i++) {
      values[i] = input.readInt();
    }
    ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
    return new NumericDocValues() {
      @Override
      public long get(int docID) {
        return values[docID];
      }
    };
View Full Code Here

    final long values[] = new long[maxDoc];
    for (int i = 0; i < values.length; i++) {
      values[i] = input.readLong();
    }
    ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
    return new NumericDocValues() {
      @Override
      public long get(int docID) {
        return values[docID];
      }
    };
View Full Code Here

    switch(type) {
      case INT:
        return new FieldComparator.IntComparator(numHits, getField(), null, (Integer) missingValue) {
          @Override
          protected FieldCache.Ints getIntValues(AtomicReaderContext context, String field) throws IOException {
            final NumericDocValues dv = SortedNumericSelector.wrap(DocValues.getSortedNumeric(context.reader(), field), selector, type);
            return new FieldCache.Ints() {
              @Override
              public int get(int docID) {
                return (int) dv.get(docID);
              }
            };
          }
        };
      case FLOAT:
        return new FieldComparator.FloatComparator(numHits, getField(), null, (Float) missingValue) {
          @Override
          protected FieldCache.Floats getFloatValues(AtomicReaderContext context, String field) throws IOException {
            final NumericDocValues dv = SortedNumericSelector.wrap(DocValues.getSortedNumeric(context.reader(), field), selector, type);
            return new FieldCache.Floats() {
              @Override
              public float get(int docID) {
                return Float.intBitsToFloat((int)dv.get(docID));
              }
            };
          }
        };
      case LONG:
        return new FieldComparator.LongComparator(numHits, getField(), null, (Long) missingValue) {
          @Override
          protected FieldCache.Longs getLongValues(AtomicReaderContext context, String field) throws IOException {
            final NumericDocValues dv = SortedNumericSelector.wrap(DocValues.getSortedNumeric(context.reader(), field), selector, type);
            return new FieldCache.Longs() {
              @Override
              public long get(int docID) {
                return dv.get(docID);
              }
            };
          }
        };
      case DOUBLE:
        return new FieldComparator.DoubleComparator(numHits, getField(), null, (Double) missingValue) {
          @Override
          protected FieldCache.Doubles getDoubleValues(AtomicReaderContext context, String field) throws IOException {
            final NumericDocValues dv = SortedNumericSelector.wrap(DocValues.getSortedNumeric(context.reader(), field), selector, type);
            return new FieldCache.Doubles() {
              @Override
              public double get(int docID) {
                return Double.longBitsToDouble(dv.get(docID));
              }
            };
          }
        };
      default:
View Full Code Here

        numericType != SortField.Type.LONG &&
        numericType != SortField.Type.FLOAT &&
        numericType != SortField.Type.DOUBLE) {
      throw new IllegalArgumentException("numericType must be a numeric type");
    }
    final NumericDocValues view;
    NumericDocValues singleton = DocValues.unwrapSingleton(sortedNumeric);
    if (singleton != null) {
      // it's actually single-valued in practice, but indexed as multi-valued,
      // so just sort on the underlying single-valued dv directly.
      // regardless of selector type, this optimization is safe!
      view = singleton;
    } else {
      switch(selector) {
        case MIN:
          view = new MinValue(sortedNumeric);
          break;
        case MAX:
          view = new MaxValue(sortedNumeric);
          break;
        default:
          throw new AssertionError();
      }
    }
    // undo the numericutils sortability
    switch(numericType) {
      case FLOAT:
        return new NumericDocValues() {
          @Override
          public long get(int docID) {
            return NumericUtils.sortableFloatBits((int) view.get(docID));
          }
        };
      case DOUBLE:
        return new NumericDocValues() {
          @Override
          public long get(int docID) {
            return NumericUtils.sortableDoubleBits(view.get(docID));
          }
        };
View Full Code Here

    }
  }

  @Override
  public synchronized NumericDocValues getNumeric(FieldInfo field) throws IOException {
    NumericDocValues instance = instances.get(field.number);
    if (instance == null) {
      instance = loadNorms(field);
      instances.put(field.number, instance);
    }
    return instance;
View Full Code Here

  private NumericDocValues loadNorms(FieldInfo field) throws IOException {
    NormsEntry entry = norms.get(field.number);
    switch(entry.format) {
      case CONST_COMPRESSED:
        final long v = entry.offset;
        return new NumericDocValues() {
          @Override
          public long get(int docID) {
            return v;
          }
        };
      case UNCOMPRESSED:
        data.seek(entry.offset);
        final byte bytes[] = new byte[maxDoc];
        data.readBytes(bytes, 0, bytes.length);
        ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(bytes));
        return new NumericDocValues() {
          @Override
          public long get(int docID) {
            return bytes[docID];
          }
        };
      case DELTA_COMPRESSED:
        data.seek(entry.offset);
        int packedIntsVersion = data.readVInt();
        int blockSize = data.readVInt();
        final BlockPackedReader reader = new BlockPackedReader(data, packedIntsVersion, blockSize, maxDoc, false);
        ramBytesUsed.addAndGet(reader.ramBytesUsed());
        return reader;
      case TABLE_COMPRESSED:
        data.seek(entry.offset);
        int packedVersion = data.readVInt();
        int size = data.readVInt();
        if (size > 256) {
          throw new CorruptIndexException("TABLE_COMPRESSED cannot have more than 256 distinct values, input=" + data);
        }
        final long decode[] = new long[size];
        for (int i = 0; i < decode.length; i++) {
          decode[i] = data.readLong();
        }
        final int formatID = data.readVInt();
        final int bitsPerValue = data.readVInt();
        final PackedInts.Reader ordsReader = PackedInts.getReaderNoHeader(data, PackedInts.Format.byId(formatID), packedVersion, maxDoc, bitsPerValue);
        ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(decode) + ordsReader.ramBytesUsed());
        return new NumericDocValues() {
          @Override
          public long get(int docID) {
            return decode[(int)ordsReader.get(docID)];
          }
        };
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.NumericDocValues

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.