float payloadBoost() throws IOException { if (doc != docID()) { final int freq = postings.freq(); payloadBoost = 0; for (int i = 0; i < freq; ++i) { postings.nextPosition(); final BytesRef payload = postings.getPayload(); float boost; if (payload == null) { boost = 1; } else if (payload.length == 1) { boost = SmallFloat.byte315ToFloat(payload.bytes[payload.offset]); } else if (payload.length == 4) { // TODO: for bw compat only, remove this in 6.0 boost = PayloadHelper.decodeFloat(payload.bytes, payload.offset); } else { throw new IllegalStateException("Payloads are expected to have a length of 1 or 4 but got: " + payload); } payloadBoost += boost; } payloadBoost /= freq; doc = docID(); } return payloadBoost; }
@Override public void collect(int doc) throws IOException { if (this.keyValues != null) { int value = (int) this.keyValues.get(doc); if (value > 0) { if (value >= this.scores.length) { this.scores = ScoreSuperCollector.resize(this.scores, (int) ((value + 1) * 1.25)); } this.scores[value] = SmallFloat.floatToByte315(scorer.score()); } } }
AllTokenStream(TokenStream input, float boost) { super(input); payloadAttribute = addAttribute(PayloadAttribute.class); payloadSpare.bytes[0] = SmallFloat.floatToByte315(boost); }
/** Encodes the length to a byte via SmallFloat. */ protected byte encodeNormValue(float boost, float length) { return SmallFloat.floatToByte315((boost / (float) Math.sqrt(length))); }
@Override protected byte encodeNormValue(float boost, int fieldLength) { return SmallFloat.floatToByte315(boost / (float) fieldLength); }
/** Encodes the length to a byte via SmallFloat. */ private static byte encodeNormValue(float boost, float length) { return SmallFloat.floatToByte315((boost / (float) Math.sqrt(length))); }
/** Encodes a normalization factor for storage in an index. */ public final long encodeNormValue(final float floatVal) { return SmallFloat.floatToByte315(floatVal); }
public float score(int key) { if (key < this.scores.length) { return SmallFloat.byte315ToFloat(this.scores[key]); } return 0; }
/** * Encodes a normalization factor for storage in an index. * <p> * The encoding uses a three-bit mantissa, a five-bit exponent, and the * zero-exponent point at 15, thus representing values from around 7x10^9 to * 2x10^-9 with about one significant decimal digit of accuracy. Zero is also * represented. Negative numbers are rounded up to zero. Values too large to * represent are rounded down to the largest representable value. Positive * values too small to represent are rounded up to the smallest positive * representable value. * * @see org.apache.lucene.document.Field#setBoost(float) * @see org.apache.lucene.util.SmallFloat */ @Override public final long encodeNormValue(float f) { return SmallFloat.floatToByte315(f); }
/** The default implementation encodes <code>boost / sqrt(length)</code> * with {@link SmallFloat#floatToByte315(float)}. This is compatible with * Lucene's default implementation. If you change this, then you should * change {@link #decodeNormValue(byte)} to match. */ protected byte encodeNormValue(float boost, int fieldLength) { return SmallFloat.floatToByte315(boost / (float) Math.sqrt(fieldLength)); }
/** * Encodes a normalization factor for storage in an index. * <p> * The encoding uses a three-bit mantissa, a five-bit exponent, and the * zero-exponent point at 15, thus representing values from around 7x10^9 to * 2x10^-9 with about one significant decimal digit of accuracy. Zero is also * represented. Negative numbers are rounded up to zero. Values too large to * represent are rounded down to the largest representable value. Positive * values too small to represent are rounded up to the smallest positive * representable value. * * @see org.apache.lucene.document.Field#setBoost(float) * @see org.apache.lucene.util.SmallFloat */ @Override public long encodeNormValue(float f) { return SmallFloat.floatToByte315(f); }
/** Encodes a normalization factor for storage in an index. * * <p>The encoding uses a three-bit mantissa, a five-bit exponent, and * the zero-exponent point at 15, thus * representing values from around 7x10^9 to 2x10^-9 with about one * significant decimal digit of accuracy. Zero is also represented. * Negative numbers are rounded up to zero. Values too large to represent * are rounded down to the largest representable value. Positive values too * small to represent are rounded up to the smallest positive representable * value. * @see org.apache.lucene.document.Field#setBoost(float) * @see org.apache.lucene.util.SmallFloat */ public byte encodeNormValue(float f) { return SmallFloat.floatToByte315(f); }
/** * The default implementation encodes <code>boost / sqrt(length)</code> with {@link * SmallFloat#floatToByte315(float)}. This is compatible with Lucene's default implementation. If * you change this, then you should change {@link #decodeNormValue(byte)} to match. */ protected byte encodeNormValue(float boost, int fieldLength) { return SmallFloat.floatToByte315(boost / (float) Math.sqrt(fieldLength)); }