Example usage for org.apache.lucene.index FieldInvertState getLength

List of usage examples for org.apache.lucene.index FieldInvertState getLength

Introduction

In this page you can find the example usage for org.apache.lucene.index FieldInvertState getLength.

Prototype

public int getLength() 

Source Link

Document

Get total number of terms in this field.

Usage

From source file:BM25LSimilarity.java

License:Apache License

@Override
public final long computeNorm(FieldInvertState state) {
    final int numTerms = discountOverlaps ? state.getLength() - state.getNumOverlap() : state.getLength();
    return encodeNormValue(state.getBoost(), numTerms);
}

From source file:com.core.nlp.similarity.DefaultSimilarity.java

License:Apache License

/**
 * Implemented as/* w  ww .  j  a va  2s. c  o m*/
 * <code>state.getBoost()*lengthNorm(numTerms)</code>, where
 * <code>numTerms</code> is {@link FieldInvertState#getLength()} if {@link
 * #setDiscountOverlaps} is false, else it's {@link
 * FieldInvertState#getLength()} - {@link
 * FieldInvertState#getNumOverlap()}.
 *
 * @lucene.experimental
 */
@Override
public float lengthNorm(FieldInvertState state) {
    final int numTerms;
    if (discountOverlaps)
        numTerms = state.getLength() - state.getNumOverlap();
    else
        numTerms = state.getLength();
    return state.getBoost() * ((float) (1.0 / Math.sqrt(numTerms)));
}

From source file:com.jaeksoft.searchlib.schema.FairSimilarity.java

License:Open Source License

@Override
final public float computeNorm(String field, FieldInvertState state) {
    final int numTerms;
    if (discountOverlaps)
        numTerms = state.getLength() - state.getNumOverlap();
    else/*w  ww .  j av  a2s  .co  m*/
        numTerms = state.getLength();
    return state.getBoost() * ((float) (1.0 / numTerms));
}

From source file:elhuyar.bilakit.SimilarityCLIRFactory.java

License:Open Source License

/** Implemented as
 *  <code>state.getBoost()*lengthNorm(numTerms)</code>, where
 *  <code>numTerms</code> is {@link FieldInvertState#getLength()} if {@link
 *  #setDiscountOverlaps} is false, else it's {@link
 *  FieldInvertState#getLength()} - {@link
 *  FieldInvertState#getNumOverlap()}./* w  ww. j ava2s  .co  m*/
 *
 *  @lucene.experimental */
public float lengthNorm(FieldInvertState state) {
    final int numTerms;
    if (discountOverlaps)
        numTerms = state.getLength() - state.getNumOverlap();
    else
        numTerms = state.getLength();
    return state.getBoost() * ((float) (1.0 / Math.sqrt(numTerms)));
}

From source file:eu.europeana.ranking.bm25f.similarity.BM25FSimilarity.java

License:Apache License

@Override
public final void computeNorm(FieldInvertState state, Norm norm) {
    final int numTerms = discountOverlaps ? state.getLength() - state.getNumOverlap() : state.getLength();
    norm.setByte(encodeNormValue(state.getBoost(), numTerms));
}

From source file:io.anserini.search.similarity.F2LogSimilarity.java

License:Apache License

@Override
public long computeNorm(FieldInvertState state) {
    final int numTerms = discountOverlaps ? state.getLength() - state.getNumOverlap() : state.getLength();
    return encodeNormValue(state.getBoost(), numTerms);
}

From source file:it.unipd.dei.ims.falcon.ranking.HashSimilarity.java

License:Apache License

@Override
/*/*from  ww w  .j a  v  a 2s  .  co m*/
 * (non-Javadoc)
 *
 * @see org.apache.lucene.search.Similarity#computeNorm(String, int)
 */
public float computeNorm(String field, FieldInvertState state) {
    return lengthNorm(field, state.getLength());
}

From source file:main.BM25VASimilarity.java

License:Apache License

@Override
public final long computeNorm(FieldInvertState state) {
    final int numTerms = discountOverlaps ? state.getLength() - state.getNumOverlap() : state.getLength();
    state.getUniqueTermCount();// w  w  w.ja  v  a2  s  .  c  o m
    //System.out.println(state.getName());
    //System.out.println(state.getUniqueTermCount());
    return encodeNormValue(state.getBoost(), numTerms);
}

From source file:org.archive.jbs.lucene.WebSimilarity.java

License:Apache License

/** Normalize field by length.  Called at index time. */
public float computeNorm(String fieldName, FieldInvertState state) {
    int numTokens = state.getLength();

    if ("url".equals(fieldName)) {
        // URL: prefer short by using linear normalization
        return 1.0f / numTokens;

    } else if ("content".equals(fieldName)) {
        // Content: penalize short, by treating short as longer

        // TODO: Is creating a new FieldInvertState object good, or
        //       should we modify the existing one?
        return super.computeNorm(fieldName,
                new FieldInvertState(state.getPosition(), Math.max(numTokens, MIN_CONTENT_LENGTH),
                        state.getNumOverlap(), state.getOffset(), state.getBoost()));
    } else {//from  w w  w  .j a v a 2 s  . c o m
        // use default
        return super.computeNorm(fieldName, state);
    }
}

From source file:org.archive.tnh.WebSimilarity.java

License:Apache License

/** Normalize field by length.  Called at index time. */
public float computeNorm(String fieldName, FieldInvertState state) {
    int numTokens = state.getLength();

    if ("url".equals(fieldName)) {
        // URL: prefer short by using linear normalization
        return 1.0f / numTokens;

    } else if ("content".equals(fieldName)) {
        // Content: penalize short, by treating short as longer
        return super.lengthNorm(fieldName, Math.max(numTokens, MIN_CONTENT_LENGTH));
    } else {/*from   ww  w  . j a v  a 2 s .c o  m*/
        // use default
        return super.lengthNorm(fieldName, numTokens);
    }
}