in src/java/com/twitter/search/earlybird/search/relevance/LinearScoringParams.java [129:303]
public LinearScoringParams(ThriftSearchQuery searchQuery, ThriftRankingParams params) {
// weights
luceneWeight = params.isSetLuceneScoreParams()
? params.getLuceneScoreParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
textScoreWeight = params.isSetTextScoreParams()
? params.getTextScoreParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
retweetWeight = params.isSetRetweetCountParams()
? params.getRetweetCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
favWeight = params.isSetFavCountParams()
? params.getFavCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
replyWeight = params.isSetReplyCountParams()
? params.getReplyCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
multipleReplyWeight = params.isSetMultipleReplyCountParams()
? params.getMultipleReplyCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
parusWeight = params.isSetParusScoreParams()
? params.getParusScoreParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
for (int i = 0; i < LinearScoringData.MAX_OFFLINE_EXPERIMENTAL_FIELDS; i++) {
Byte featureTypeByte = (byte) i;
// default weight is 0, thus contribution for unset feature value will be 0.
rankingOfflineExpWeights[i] = params.getOfflineExperimentalFeatureRankingParamsSize() > 0
&& params.getOfflineExperimentalFeatureRankingParams().containsKey(featureTypeByte)
? params.getOfflineExperimentalFeatureRankingParams().get(featureTypeByte).getWeight()
: DEFAULT_FEATURE_WEIGHT;
}
embedsImpressionWeight = params.isSetEmbedsImpressionCountParams()
? params.getEmbedsImpressionCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
embedsUrlWeight = params.isSetEmbedsUrlCountParams()
? params.getEmbedsUrlCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
videoViewWeight = params.isSetVideoViewCountParams()
? params.getVideoViewCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
quotedCountWeight = params.isSetQuotedCountParams()
? params.getQuotedCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
applyBoosts = params.isApplyBoosts();
// configure card values
Arrays.fill(hasCardBoosts, DEFAULT_NO_BOOST);
Arrays.fill(cardAuthorMatchBoosts, DEFAULT_NO_BOOST);
Arrays.fill(cardDomainMatchBoosts, DEFAULT_NO_BOOST);
Arrays.fill(cardTitleMatchBoosts, DEFAULT_NO_BOOST);
Arrays.fill(cardDescriptionMatchBoosts, DEFAULT_NO_BOOST);
if (params.isSetCardRankingParams()) {
for (SearchCardType cardType : SearchCardType.values()) {
byte cardTypeIndex = cardType.getByteValue();
ThriftCardRankingParams rankingParams = params.getCardRankingParams().get(cardTypeIndex);
if (rankingParams != null) {
hasCardBoosts[cardTypeIndex] = rankingParams.getHasCardBoost();
cardAuthorMatchBoosts[cardTypeIndex] = rankingParams.getAuthorMatchBoost();
cardDomainMatchBoosts[cardTypeIndex] = rankingParams.getDomainMatchBoost();
cardTitleMatchBoosts[cardTypeIndex] = rankingParams.getTitleMatchBoost();
cardDescriptionMatchBoosts[cardTypeIndex] = rankingParams.getDescriptionMatchBoost();
}
}
}
urlWeight = params.isSetUrlParams()
? params.getUrlParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
reputationWeight = params.isSetReputationParams()
? params.getReputationParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
isReplyWeight = params.isSetIsReplyParams()
? params.getIsReplyParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
followRetweetWeight = params.isSetDirectFollowRetweetCountParams()
? params.getDirectFollowRetweetCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
trustedRetweetWeight = params.isSetTrustedCircleRetweetCountParams()
? params.getTrustedCircleRetweetCountParams().getWeight() : DEFAULT_FEATURE_WEIGHT;
querySpecificScoreAdjustments = params.getQuerySpecificScoreAdjustments();
authorSpecificScoreAdjustments = params.getAuthorSpecificScoreAdjustments();
// min/max filters
textScoreMinVal = params.isSetTextScoreParams()
? params.getTextScoreParams().getMin() : DEFAULT_FEATURE_MIN_VAL;
reputationMinVal = params.isSetReputationParams()
? params.getReputationParams().getMin() : DEFAULT_FEATURE_MIN_VAL;
multipleReplyMinVal = params.isSetMultipleReplyCountParams()
? params.getMultipleReplyCountParams().getMin() : DEFAULT_FEATURE_MIN_VAL;
retweetMinVal = params.isSetRetweetCountParams() && params.getRetweetCountParams().isSetMin()
? params.getRetweetCountParams().getMin() : DEFAULT_FEATURE_MIN_VAL;
favMinVal = params.isSetFavCountParams() && params.getFavCountParams().isSetMin()
? params.getFavCountParams().getMin() : DEFAULT_FEATURE_MIN_VAL;
// boosts
spamUserDamping = params.isSetSpamUserBoost() ? params.getSpamUserBoost() : 1.0;
nsfwUserDamping = params.isSetNsfwUserBoost() ? params.getNsfwUserBoost() : 1.0;
botUserDamping = params.isSetBotUserBoost() ? params.getBotUserBoost() : 1.0;
offensiveDamping = params.getOffensiveBoost();
trustedCircleBoost = params.getInTrustedCircleBoost();
directFollowBoost = params.getInDirectFollowBoost();
// language boosts
langEnglishTweetDemote = params.getLangEnglishTweetBoost();
langEnglishUIDemote = params.getLangEnglishUIBoost();
langDefaultDemote = params.getLangDefaultBoost();
useUserLanguageInfo = params.isUseUserLanguageInfo();
unknownLanguageBoost = params.getUnknownLanguageBoost();
// hit demotions
enableHitDemotion = params.isEnableHitDemotion();
noTextHitDemotion = params.getNoTextHitDemotion();
urlOnlyHitDemotion = params.getUrlOnlyHitDemotion();
nameOnlyHitDemotion = params.getNameOnlyHitDemotion();
separateTextAndNameHitDemotion = params.getSeparateTextAndNameHitDemotion();
separateTextAndUrlHitDemotion = params.getSeparateTextAndUrlHitDemotion();
outOfNetworkReplyPenalty = params.getOutOfNetworkReplyPenalty();
if (params.isSetAgeDecayParams()) {
// new age decay settings
ThriftAgeDecayRankingParams ageDecayParams = params.getAgeDecayParams();
ageDecaySlope = ageDecayParams.getSlope();
ageDecayHalflife = ageDecayParams.getHalflife();
ageDecayBase = ageDecayParams.getBase();
useAgeDecay = true;
} else if (params.isSetDeprecatedAgeDecayBase()
&& params.isSetDeprecatedAgeDecayHalflife()
&& params.isSetDeprecatedAgeDecaySlope()) {
ageDecaySlope = params.getDeprecatedAgeDecaySlope();
ageDecayHalflife = params.getDeprecatedAgeDecayHalflife();
ageDecayBase = params.getDeprecatedAgeDecayBase();
useAgeDecay = true;
} else {
ageDecaySlope = 0.0;
ageDecayHalflife = 0.0;
ageDecayBase = 0.0;
useAgeDecay = false;
}
// trends
tweetHasTrendBoost = params.getTweetHasTrendBoost();
multipleHashtagsOrTrendsDamping = params.getMultipleHashtagsOrTrendsBoost();
// verified accounts
tweetFromVerifiedAccountBoost = params.getTweetFromVerifiedAccountBoost();
tweetFromBlueVerifiedAccountBoost = params.getTweetFromBlueVerifiedAccountBoost();
// score filter
minScore = params.getMinScore();
applyFiltersAlways = params.isApplyFiltersAlways();
useLuceneScoreAsBoost = params.isUseLuceneScoreAsBoost();
maxLuceneScoreBoost = params.getMaxLuceneScoreBoost();
searcherId = searchQuery.isSetSearcherId() ? searchQuery.getSearcherId() : -1;
selfTweetBoost = params.getSelfTweetBoost();
socialFilterType = searchQuery.getSocialFilterType();
// the UI language and the confidences of the languages user can understand.
if (!searchQuery.isSetUiLang() || searchQuery.getUiLang().isEmpty()) {
uiLangId = ThriftLanguage.UNKNOWN.getValue();
} else {
uiLangId = ThriftLanguageUtil.getThriftLanguageOf(searchQuery.getUiLang()).getValue();
}
if (searchQuery.getUserLangsSize() > 0) {
for (Map.Entry<ThriftLanguage, Double> lang : searchQuery.getUserLangs().entrySet()) {
ThriftLanguage thriftLanguage = lang.getKey();
// SEARCH-13441
if (thriftLanguage != null) {
userLangs[thriftLanguage.getValue()] = lang.getValue();
} else {
NULL_USER_LANGS_KEY.increment();
}
}
}
// For now, we will use the same boost for both image, and video.
tweetHasMediaUrlBoost = params.getTweetHasImageUrlBoost();
tweetHasNewsUrlBoost = params.getTweetHasNewsUrlBoost();
getInReplyToStatusId =
searchQuery.isSetResultMetadataOptions()
&& searchQuery.getResultMetadataOptions().isSetGetInReplyToStatusId()
&& searchQuery.getResultMetadataOptions().isGetInReplyToStatusId();
}