static DefaultSimilarity() { for (int i = 0; i < 256; i++) { NORM_TABLE[i] = SmallSingle.SByte315ToSingle((sbyte)i); } }
static BM25Similarity() { for (int i = 0; i < 256; i++) { float f = SmallSingle.SByte315ToSingle((sbyte)i); NORM_TABLE[i] = 1.0f / (f * f); } }
private static float[] LoadNormTable() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { float[] normTable = new float[256]; for (int i = 0; i < 256; i++) { normTable[i] = SmallSingle.SByte315ToSingle((sbyte)i); } return(normTable); }
/// <summary> /// Encodes a normalization factor for storage in an index. /// <para/> /// 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. /// </summary> /// <seealso cref="Lucene.Net.Documents.Field.Boost"/> /// <seealso cref="Lucene.Net.Util.SmallSingle"/> public override sealed long EncodeNormValue(float f) { return(SmallSingle.SingleToSByte315(f)); }
/// <summary> /// The default implementation encodes <c>boost / sqrt(length)</c> /// with <see cref="SmallSingle.SingleToByte315(float)"/>. This is compatible with /// Lucene's default implementation. If you change this, then you should /// change <see cref="DecodeNormValue(byte)"/> to match. /// </summary> protected internal virtual byte EncodeNormValue(float boost, int fieldLength) { return(SmallSingle.SingleToByte315(boost / (float)Math.Sqrt(fieldLength))); }