Java Code Examples for org.apache.lucene.util.NumericUtils#sortableDoubleBits()

The following examples show how to use org.apache.lucene.util.NumericUtils#sortableDoubleBits() . 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<?> getDoubleComparator(int numHits) {
  return new FieldComparator.DoubleComparator(numHits, getField(), (Double) 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.sortableDoubleBits(super.longValue());
        }
      };
    }
  };
}
 
Example 2
Source File: SortedNumericSelector.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** 
 * Wraps a multi-valued SortedNumericDocValues as a single-valued view, using the specified selector 
 * and numericType.
 */
public static NumericDocValues wrap(SortedNumericDocValues sortedNumeric, Type selector, SortField.Type numericType) {
  if (numericType != SortField.Type.INT &&
      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 FilterNumericDocValues(view) {
        @Override
        public long longValue() throws IOException {
          return NumericUtils.sortableFloatBits((int) in.longValue());
        }
      };
    case DOUBLE:
      return new FilterNumericDocValues(view) {
        @Override
        public long longValue() throws IOException {
          return NumericUtils.sortableDoubleBits(in.longValue());
        }
      };
    default:
      return view;
  }
}
 
Example 3
Source File: FieldCache.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public long parseValue(BytesRef point) {
  return NumericUtils.sortableDoubleBits(NumericUtils.sortableBytesToLong(point.bytes, point.offset));
}
 
Example 4
Source File: FacetRangeProcessor.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public long bitsToSortableBits(long bits) {
  return NumericUtils.sortableDoubleBits(bits);
}
 
Example 5
Source File: FacetRangeProcessor.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public long bitsToSortableBits(long bits) {
  return NumericUtils.sortableDoubleBits(bits);
}