the-algorithm/pushservice/src/main/scala/com/twitter/frigate/pushservice/rank/PushserviceRanker.scala
twitter-team b389c3d302 Open-sourcing pushservice
Pushservice is the main recommendation service we use to surface recommendations to our users via notifications. It fetches candidates from various sources, ranks them in order of relevance, and applies filters to determine the best one to send.
2023-05-19 16:27:07 -05:00

32 lines
966 B
Scala

package com.twitter.frigate.pushservice.rank
import com.twitter.frigate.common.base.CandidateDetails
import com.twitter.frigate.common.base.Ranker
import com.twitter.util.Future
trait PushserviceRanker[T, C] extends Ranker[T, C] {
/**
* Initial Ranking of input candidates
*/
def initialRank(target: T, candidates: Seq[CandidateDetails[C]]): Future[Seq[CandidateDetails[C]]]
/**
* Re-ranks input ranked candidates. Useful when a subset of candidates are ranked
* by a different logic, while preserving the initial ranking for the rest
*/
def reRank(
target: T,
rankedCandidates: Seq[CandidateDetails[C]]
): Future[Seq[CandidateDetails[C]]]
/**
* Final ranking that does Initial + Rerank
*/
override final def rank(target: T, candidates: Seq[CandidateDetails[C]]): (
Future[Seq[CandidateDetails[C]]]
) = {
initialRank(target, candidates).flatMap { rankedCandidates => reRank(target, rankedCandidates) }
}
}