Skip to content

Instantly share code, notes, and snippets.

@algesten
Created June 27, 2013 06:55
Show Gist options
  • Save algesten/5874476 to your computer and use it in GitHub Desktop.
Save algesten/5874476 to your computer and use it in GitHub Desktop.
Similarity that disregards the length of the field.
private final static Similarity NO_LENGTH_SIMILARITY = new DefaultSimilarity() {
// we are interested in length norm for the street number field.
// it's good if 10 is sorted before 10a and 10b.
//
// the "country" field is very important it has no document boost since that means
// simply turning Query.setCountry() on will make a different score. This is because
// a document boost will add to every field and country is matched in a MUST.
@Override
public float computeNorm(String field, FieldInvertState state) {
if (AddressImpl.Fields.STREET_NO.iname().equals(field)) {
return super.computeNorm(field, state);
} else {
return state.getBoost();
}
}
// overridden to return 1.0f
@Override
public float idf(int docFreq, int numDocs) {
return 1.0f;
}
// overridden to return 1.0f
@Override
public float queryNorm(float sumOfSquaredWeights) {
return 1.0f;
};
// overridden to return 1.0f
@Override
public float coord(int overlap, int maxOverlap) {
return 1.0f;
};
// overridden to return 1.0f
@Override
public float tf(float freq) {
return 1.0f;
}
// we only expect values to be integer between 0-100
@Override
public byte encodeNormValue(float f) {
return (byte) f;
}
@Override
public float decodeNormValue(byte b) {
return (float) b;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment