the-algorithm/src/java/com/twitter/search/earlybird/search/relevance/scoring/DefaultScoringFunction.java
twitter-team ef4c5eb65e Twitter Recommendation Algorithm
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
2023-03-31 17:36:31 -05:00

38 lines
1.1 KiB
Java

package com.twitter.search.earlybird.search.relevance.scoring;
import org.apache.lucene.search.Explanation;
import com.twitter.search.common.schema.base.ImmutableSchemaInterface;
import com.twitter.search.earlybird.thrift.ThriftSearchResultsRelevanceStats;
/*
* A sample scorer, doesn't really do anything, returns the same score for every document.
*/
public class DefaultScoringFunction extends ScoringFunction {
private float score;
public DefaultScoringFunction(ImmutableSchemaInterface schema) {
super(schema);
}
@Override
protected float score(float luceneQueryScore) {
score = luceneQueryScore;
return luceneQueryScore;
}
@Override
protected Explanation doExplain(float luceneScore) {
// just an example - this scoring function will go away soon
return Explanation.match(luceneScore, "luceneScore=" + luceneScore);
}
@Override
public void updateRelevanceStats(ThriftSearchResultsRelevanceStats relevanceStats) {
relevanceStats.setNumScored(relevanceStats.getNumScored() + 1);
if (score == ScoringFunction.SKIP_HIT) {
relevanceStats.setNumSkipped(relevanceStats.getNumSkipped() + 1);
}
}
}