How can I convert this Similariity method to use 3.1 (currently using
3.0.3), I understand I have to replace lengthNorm() wuth computerNorm()
, but fieldlName is not a provided parameter in computerNorm() and
FieldInvertState does not contain the fieldname either. I need the field
because I only want to make this adjustment for a particular field in
the index not all fields, and I don't believe there is anything in the
api at the moment to let you set similarity at a field level.
public class MusicbrainzSimilarity extends DefaultSimilarity {
/**
* Calculates a value which is inversely proportional to the number
of terms in the field. When multiple
* aliases are added to an artist (or label) it is seen as one
field, so artists with many aliases can be
* disadvantaged against when the matching alias is radically
different to other aliases.
*
* @return score component
*/
@Override
public float lengthNorm(String fieldName, int numTerms) {
if (fieldName.equals("alias")) {
return 0.578f; //Same result as normal calc if field had
three terms the most common scenario
} else {
return super.lengthNorm(fieldName, numTerms);
}
}
/**
* This method calculates a value based on how many times the
search term was found in the field. Because
* we have only short fields the only real case (apart from rare
exceptions like Duran Duran Duran) whereby
* the term term is found more than twice would be when
* a search term matches multiples aliases, to remove the bias this
gives towards artists/labels with
* many aliases we limit the value to what would be returned for a
two term match.
*
* Note: would prefer to do this just for alias field, but the
field is not passed as a parameter.
* @param freq
* @return score component
*/
@Override
public float tf(float freq) {
if (freq > 2.0f) {
return 1.41f; //Same result as if matched term twice
} else {
return super.tf(freq);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org