org.apache.lucene.util.SmallFloat Java Examples

The following examples show how to use org.apache.lucene.util.SmallFloat. 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: SimilarityBase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Encodes the document length in the same way as {@link BM25Similarity}. */
@Override
public final long computeNorm(FieldInvertState state) {
  final int numTerms;
  if (state.getIndexOptions() == IndexOptions.DOCS && state.getIndexCreatedVersionMajor() >= 8) {
    numTerms = state.getUniqueTermCount();
  } else if (discountOverlaps) {
    numTerms = state.getLength() - state.getNumOverlap();
  } else {
    numTerms = state.getLength();
  }
  return SmallFloat.intToByte4(numTerms);
}
 
Example #2
Source File: BM25Similarity.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public final long computeNorm(FieldInvertState state) {
  final int numTerms;
  if (state.getIndexOptions() == IndexOptions.DOCS && state.getIndexCreatedVersionMajor() >= 8) {
    numTerms = state.getUniqueTermCount();
  } else if (discountOverlaps) {
    numTerms = state.getLength() - state.getNumOverlap();
  } else {
    numTerms = state.getLength();
  }
  return SmallFloat.intToByte4(numTerms);
}
 
Example #3
Source File: TFIDFSimilarity.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public final long computeNorm(FieldInvertState state) {
  final int numTerms;
  if (state.getIndexOptions() == IndexOptions.DOCS && state.getIndexCreatedVersionMajor() >= 8) {
    numTerms = state.getUniqueTermCount();
  } else if (discountOverlaps) {
    numTerms = state.getLength() - state.getNumOverlap();
  } else {
    numTerms = state.getLength();
  }
  return SmallFloat.intToByte4(numTerms);
}
 
Example #4
Source File: LindenSimilarity.java    From linden with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: BM25Similarity.java    From lucene4ir with Apache License 2.0 2 votes vote down vote up
/** 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));
}