|
@@ -0,0 +1,547 @@
|
|
|
+package com.tzld.piaoquan.recommend.framework.common.item;
|
|
|
+
|
|
|
+import com.google.common.base.Joiner;
|
|
|
+import com.google.common.base.Predicate;
|
|
|
+import com.google.common.collect.Iterables;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.tzld.piaoquan.recommend.framework.retrieve.candidate.CandidateInfo;
|
|
|
+
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+
|
|
|
+
|
|
|
+public class RankerItem implements Comparable<RankerItem> {
|
|
|
+ private String id = "";
|
|
|
+ private String originDocId = ""; // 原始docid
|
|
|
+ private double score = 0; // 最终的score
|
|
|
+ private double l3score = -1; // 索引中的score值
|
|
|
+ private double recScore; // 精排ctr模型 打分
|
|
|
+ private double dwelltimeScore; // 停留时长打分
|
|
|
+ private double completenessScore;
|
|
|
+ private double pCtrBScore; // 粗排ctr模型 打分
|
|
|
+ private int l3ScoreIndex;
|
|
|
+ private String reason;
|
|
|
+ private String queue;
|
|
|
+ private CandidateInfo candidateInfo;
|
|
|
+ private List<CandidateInfo> candidateInfoList; // 兼容多个召回key命中
|
|
|
+ private Object itemInfo;
|
|
|
+ private Object itemInfoBytes;
|
|
|
+ private Map<String, String> flags;
|
|
|
+ private Map<String, Double> rankerScore;
|
|
|
+ private Map<String, Integer> rankerIndex;
|
|
|
+ private Map<String, String> itemInfoDebug;
|
|
|
+ // item 信息
|
|
|
+ private long exposeCount;
|
|
|
+ private long clickCount;
|
|
|
+ // merger 信息
|
|
|
+ private List<String> mergeQueuePath;
|
|
|
+ private List<String> mergeDecisionLabels;
|
|
|
+ // reason
|
|
|
+ private String reasonByClickItemId = "";
|
|
|
+ private String reasonBySearchTags = "";
|
|
|
+ private String reasonByExploitTags = "";
|
|
|
+ private String reasonByExploreTags = "";
|
|
|
+ // 排序因子
|
|
|
+ private Map<String, Double> rankItemCategories = Maps.newHashMap();
|
|
|
+ private Map<String, Double> rankItemSubCategories = Maps.newHashMap();
|
|
|
+ private Map<String, Double> rankItemUserTags = Maps.newHashMap();
|
|
|
+ private Map<String, Double> rankItemTitleTags = Maps.newHashMap();
|
|
|
+ private String source;
|
|
|
+ // for L3Score
|
|
|
+ private int index;// 无意义
|
|
|
+ // for feature debug
|
|
|
+ private Map<String, String> ctrFeaWeight;
|
|
|
+ private Map<String, String> dwellTimeFeaWeight;
|
|
|
+ private Map<String, String> dnnCtrFeaWeight;
|
|
|
+ private Map<String, String> completenessFeaWeight;
|
|
|
+
|
|
|
+ private List<Long> w2vTopics;
|
|
|
+ private List<Long> LDATopics;
|
|
|
+ private Map<String, Double> rankedTags;
|
|
|
+
|
|
|
+ public RankerItem() {
|
|
|
+ this.rankerIndex = new HashMap<String, Integer>();
|
|
|
+ this.rankerScore = new HashMap<String, Double>();
|
|
|
+ this.itemInfoDebug = new HashMap<String, String>();
|
|
|
+ this.mergeQueuePath = new LinkedList<String>();
|
|
|
+ this.mergeDecisionLabels = new LinkedList<String>();
|
|
|
+ this.ctrFeaWeight = new HashMap<String, String>();
|
|
|
+ this.dwellTimeFeaWeight = new HashMap<String, String>();
|
|
|
+ this.dnnCtrFeaWeight = new HashMap<String, String>();
|
|
|
+ this.candidateInfoList = new ArrayList<CandidateInfo>();
|
|
|
+ this.completenessFeaWeight = new HashMap<String, String>();
|
|
|
+ this.w2vTopics = new ArrayList<>();
|
|
|
+ this.LDATopics = new ArrayList<>();
|
|
|
+ this.rankedTags = new HashMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public RankerItem(RankerItem other) {
|
|
|
+
|
|
|
+ // 涉及到变更的字段
|
|
|
+ this.id = other.getId();
|
|
|
+ this.originDocId = other.getOriginDocId();
|
|
|
+ this.score = other.getScore();
|
|
|
+ this.l3score = other.getL3score();
|
|
|
+ this.recScore = other.getRecScore();
|
|
|
+ this.pCtrBScore = other.getPCtrBScore();
|
|
|
+ this.dwelltimeScore = other.getDwelltimeScore();
|
|
|
+ this.l3ScoreIndex = other.getL3ScoreIndex();
|
|
|
+
|
|
|
+ this.reason = other.getReason();
|
|
|
+ this.queue = other.getQueue();
|
|
|
+
|
|
|
+ // item 信息
|
|
|
+ this.exposeCount = other.exposeCount;
|
|
|
+ this.clickCount = other.clickCount;
|
|
|
+
|
|
|
+ // merger 信息
|
|
|
+ this.mergeQueuePath = Lists.newArrayList();
|
|
|
+ this.mergeDecisionLabels = Lists.newArrayList();
|
|
|
+ if (other.getMergeQueuePath() != null)
|
|
|
+ this.mergeQueuePath.addAll(other.getMergeQueuePath());
|
|
|
+ if (other.getMergeDecisionLabels() != null)
|
|
|
+ this.mergeDecisionLabels.addAll(other.getMergeDecisionLabels());
|
|
|
+
|
|
|
+ this.rankedTags = new HashMap<>();
|
|
|
+ if (other.getRankedTags() != null) {
|
|
|
+ this.rankedTags.putAll(other.getRankedTags());
|
|
|
+ }
|
|
|
+
|
|
|
+ this.reasonByClickItemId = other.getReasonByClickItemId();
|
|
|
+ this.reasonBySearchTags = other.getReasonBySearchTags();
|
|
|
+ this.reasonByExploitTags = other.getReasonByExploitTags();
|
|
|
+ this.reasonByExploreTags = other.getReasonByExploreTags();
|
|
|
+
|
|
|
+ // candidateinfo
|
|
|
+ this.candidateInfo = other.getCandidateInfo() != null ? other.getCandidateInfo().deepcopy() : null;
|
|
|
+ this.candidateInfoList = Lists.newArrayList();
|
|
|
+ if (other.getCandidateInfoList() != null) {
|
|
|
+ for (CandidateInfo tmpCandidateInfo : other.getCandidateInfoList()) {
|
|
|
+ this.candidateInfoList.add(tmpCandidateInfo.deepcopy());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 只读字段
|
|
|
+ this.itemInfo = other.getItemInfo();
|
|
|
+ this.itemInfoBytes = other.getItemInfoBytes();
|
|
|
+ this.candidateInfoList = other.getCandidateInfoList(); // 兼容多个召回key命中
|
|
|
+
|
|
|
+ this.rankItemCategories = other.getRankItemCategories();
|
|
|
+ this.rankItemSubCategories = other.getRankItemSubCategories();
|
|
|
+ this.rankItemUserTags = other.getRankItemUserTags();
|
|
|
+ this.rankItemTitleTags = other.getRankItemTitleTags();
|
|
|
+ this.source = other.getSource();
|
|
|
+
|
|
|
+ this.ctrFeaWeight = other.getCtrFeaWeight();
|
|
|
+ this.dwellTimeFeaWeight = other.getDwellTimeFeaWeight();
|
|
|
+ this.completenessFeaWeight = other.getCompletenessFeaWeight();
|
|
|
+ this.dnnCtrFeaWeight = other.getDnnCtrFeaWeight();
|
|
|
+
|
|
|
+ this.rankerScore = other.getRankerScore();
|
|
|
+ this.rankerIndex = other.getRankerIndex();
|
|
|
+ this.itemInfoDebug = other.getItemInfoDebug();
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getPCtrBScore() {
|
|
|
+ return pCtrBScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setPCtrBScore(double pCtrBScore) {
|
|
|
+ this.pCtrBScore = pCtrBScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public RankerItem deepcopy() {
|
|
|
+ return new RankerItem(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<CandidateInfo> getCandidateInfoList() {
|
|
|
+ return candidateInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCandidateInfoList(List<CandidateInfo> candidateInfoList) {
|
|
|
+ this.candidateInfoList = candidateInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addToCandidateInfoList(CandidateInfo candidateInfo) {
|
|
|
+ this.candidateInfoList.add(candidateInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void putCtrFeaWeight(String featureName, double weight) {
|
|
|
+ this.ctrFeaWeight.put(featureName, Double.toString(weight));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void putAllCtrFeaWeight(Map<String, Double> featureMap) {
|
|
|
+ for (Map.Entry<String, Double> entry : featureMap.entrySet()) {
|
|
|
+ this.ctrFeaWeight.put(entry.getKey(), Double.toString(entry.getValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void putDwellTimeFeaWeight(String featureName, double weight) {
|
|
|
+ this.dwellTimeFeaWeight.put(featureName, Double.toString(weight));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void putAllDwellTimeFeaWeight(Map<String, Double> featureMap) {
|
|
|
+ for (Map.Entry<String, Double> entry : featureMap.entrySet()) {
|
|
|
+ this.dwellTimeFeaWeight.put(entry.getKey(), Double.toString(entry.getValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void putCompletenessFeaWeight(String featureName, double weight) {
|
|
|
+ this.completenessFeaWeight.put(featureName, Double.toString(weight));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void putAllCompletenessFeaWeight(Map<String, Double> featureMap) {
|
|
|
+ for (Map.Entry<String, Double> entry : featureMap.entrySet()) {
|
|
|
+ this.completenessFeaWeight.put(entry.getKey(), Double.toString(entry.getValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void putDnnCtrFeaWeight(Map<String, Map<String, String>> featureMap) {
|
|
|
+ for (Map.Entry<String, Map<String, String>> feaWeight : featureMap.entrySet()) {
|
|
|
+ Map<String, String> feaWeightMap = feaWeight.getValue();
|
|
|
+ this.dnnCtrFeaWeight = feaWeightMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getCtrFeaWeight() {
|
|
|
+ return ctrFeaWeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getDwellTimeFeaWeight() {
|
|
|
+ return dwellTimeFeaWeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getCompletenessFeaWeight() {
|
|
|
+ return completenessFeaWeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getDnnCtrFeaWeight() {
|
|
|
+ return dnnCtrFeaWeight;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Double> getRankItemUserTags() {
|
|
|
+ return rankItemUserTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRankItemUserTags(Map<String, Double> rankItemUserTags) {
|
|
|
+ this.rankItemUserTags = rankItemUserTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Double> getRankItemTitleTags() {
|
|
|
+ return rankItemTitleTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRankItemTitleTags(Map<String, Double> rankItemTitleTags) {
|
|
|
+ this.rankItemTitleTags = rankItemTitleTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Double> getRankItemCategories() {
|
|
|
+ return rankItemCategories;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRankItemCategories(Map<String, Double> rankItemCategories) {
|
|
|
+ this.rankItemCategories = rankItemCategories;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Double> getRankItemSubCategories() {
|
|
|
+ return rankItemSubCategories;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRankItemSubCategories(Map<String, Double> rankItemSubCategories) {
|
|
|
+ this.rankItemSubCategories = rankItemSubCategories;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getIndex() {
|
|
|
+ return index;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setIndex(int index) {
|
|
|
+ this.index = index;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getL3score() {
|
|
|
+ return l3score;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setL3score(double l3score) {
|
|
|
+ this.l3score = l3score;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getId() {
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setId(String id) {
|
|
|
+ this.id = id;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getScore() {
|
|
|
+ return score;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setScore(double score) {
|
|
|
+ this.score = score;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getDwelltimeScore() {
|
|
|
+ return dwelltimeScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setDwelltimeScore(double dwelltimeScore) {
|
|
|
+ this.dwelltimeScore = dwelltimeScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getCompletenessScore() {
|
|
|
+ return completenessScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCompletenessScore(double completenessScore) {
|
|
|
+ this.completenessScore = completenessScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public CandidateInfo getCandidateInfo() {
|
|
|
+ return candidateInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCandidateInfo(CandidateInfo candidateInfo) {
|
|
|
+ this.candidateInfo = candidateInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getFlags() {
|
|
|
+ return flags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setFlags(Map<String, String> flags) {
|
|
|
+ this.flags = flags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getReason() {
|
|
|
+ return reason;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setReason(String reason) {
|
|
|
+ this.reason = reason;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getQueue() {
|
|
|
+ return queue;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setQueue(String queue) {
|
|
|
+ this.queue = queue;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getSource() {
|
|
|
+ return source;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setSource(String source) {
|
|
|
+ this.source = source;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object getItemInfo() {
|
|
|
+ return itemInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setItemInfo(Object itemInfo) {
|
|
|
+ this.itemInfo = itemInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object getItemInfoBytes() {
|
|
|
+ return itemInfoBytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setItemInfoBytes(Object itemInfoBytes) {
|
|
|
+ this.itemInfoBytes = itemInfoBytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getRecScore() {
|
|
|
+ return recScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRecScore(double recScore) {
|
|
|
+ this.recScore = recScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getL3ScoreIndex() {
|
|
|
+ return l3ScoreIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setL3ScoreIndex(int l3ScoreIndex) {
|
|
|
+ this.l3ScoreIndex = l3ScoreIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Integer> getRankerIndex() {
|
|
|
+ return rankerIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRankerIndex(Map<String, Integer> rankerIndex) {
|
|
|
+ this.rankerIndex = rankerIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void putRankerIndex(String rankerName, Integer rankerIndex) {
|
|
|
+ this.rankerIndex.put(rankerName, rankerIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Double> getRankerScore() {
|
|
|
+ return rankerScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRankerScore(Map<String, Double> rankerScore) {
|
|
|
+ this.rankerScore = rankerScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void putRankerScore(String rankerName, Double rankerScore) {
|
|
|
+ this.rankerScore.put(rankerName, rankerScore);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getItemInfoDebug() {
|
|
|
+ return this.itemInfoDebug;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setItemInfoDebug(Map<String, String> itemInfoDebug) {
|
|
|
+ this.itemInfoDebug = itemInfoDebug;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addMergeQueuePath(String mergeQueueName) {
|
|
|
+ this.mergeQueuePath.add(mergeQueueName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> getMergeQueuePath() {
|
|
|
+ return this.mergeQueuePath;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getLastMergeQueueName() {
|
|
|
+ int pathSize = this.mergeQueuePath.size();
|
|
|
+ if (pathSize > 0) {
|
|
|
+ return this.mergeQueuePath.get(pathSize - 1);
|
|
|
+ } else {
|
|
|
+ return getCandidateInfo().getCandidate_queue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addMergeDecisionLabel(String label) {
|
|
|
+ this.mergeDecisionLabels.add(label);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> getMergeDecisionLabels() {
|
|
|
+ return this.mergeDecisionLabels;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getReasonByClickItemId() {
|
|
|
+ return reasonByClickItemId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setReasonByClickItemId(String reasonByClickItemId) {
|
|
|
+ this.reasonByClickItemId = reasonByClickItemId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getReasonBySearchTags() {
|
|
|
+ return reasonBySearchTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setReasonBySearchTags(String reasonBySearchTags) {
|
|
|
+ this.reasonBySearchTags = reasonBySearchTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getReasonByExploitTags() {
|
|
|
+ return reasonByExploitTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setReasonByExploitTags(String reasonByExploitTags) {
|
|
|
+ this.reasonByExploitTags = reasonByExploitTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getReasonByExploreTags() {
|
|
|
+ return reasonByExploreTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setReasonByExploreTags(String reasonByExploreTags) {
|
|
|
+ this.reasonByExploreTags = reasonByExploreTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getOriginDocId() {
|
|
|
+ return originDocId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setOriginDocId(String originDocId) {
|
|
|
+ this.originDocId = originDocId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getExposeCount() {
|
|
|
+ return exposeCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setExposeCount(long exposeCount) {
|
|
|
+ this.exposeCount = exposeCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getClickCount() {
|
|
|
+ return clickCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setClickCount(long clickCount) {
|
|
|
+ this.clickCount = clickCount;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Double> getRankedTags() {
|
|
|
+ return rankedTags;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRankedTags(Map<String, Double> rankedTags) {
|
|
|
+ this.rankedTags = rankedTags;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setLDATopics(List<Long> LDATopics) {
|
|
|
+ this.LDATopics = LDATopics;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转化为RecommendItem
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ StringBuffer buf = new StringBuffer();
|
|
|
+ buf.append("id: " + id);
|
|
|
+ buf.append(",");
|
|
|
+ buf.append("score: " + score);
|
|
|
+ buf.append(",");
|
|
|
+ buf.append("queue: " + queue);
|
|
|
+ return buf.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compareTo(RankerItem o) {
|
|
|
+ if (o == null) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (score > o.score) {
|
|
|
+ return -1;
|
|
|
+ } else if (score < o.score) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|