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

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

Introduction

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

Prototype

public int getPosition() 

Source Link

Document

Get the last processed term position.

Usage

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  ww .j  a  v a 2 s  . c  o  m*/
        // use default
        return super.computeNorm(fieldName, state);
    }
}