the-algorithm/timelineranker/server/src/main/scala/com/twitter/timelineranker/common/RecapHydrationSearchResultsTransformBase.scala
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

30 lines
1.0 KiB
Scala

package com.twitter.timelineranker.common
import com.twitter.finagle.stats.StatsReceiver
import com.twitter.servo.util.FutureArrow
import com.twitter.timelineranker.core.CandidateEnvelope
import com.twitter.timelines.clients.relevance_search.SearchClient
import com.twitter.timelines.model.TweetId
import com.twitter.util.Future
trait RecapHydrationSearchResultsTransformBase
extends FutureArrow[CandidateEnvelope, CandidateEnvelope] {
protected def statsReceiver: StatsReceiver
protected def searchClient: SearchClient
private[this] val numResultsFromSearchStat = statsReceiver.stat("numResultsFromSearch")
def tweetIdsToHydrate(envelope: CandidateEnvelope): Seq[TweetId]
override def apply(envelope: CandidateEnvelope): Future[CandidateEnvelope] = {
searchClient
.getTweetsScoredForRecap(
envelope.query.userId,
tweetIdsToHydrate(envelope),
envelope.query.earlybirdOptions
).map { results =>
numResultsFromSearchStat.add(results.size)
envelope.copy(searchResults = results)
}
}
}