the-algorithm/src/scala/com/twitter/recos/user_video_graph/util/FetchRHSTweetsUtil.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
913 B
Scala

package com.twitter.recos.user_video_graph.util
import com.twitter.graphjet.bipartite.MultiSegmentIterator
import com.twitter.graphjet.bipartite.api.BipartiteGraph
import com.twitter.graphjet.bipartite.segment.BipartiteGraphSegment
import scala.collection.mutable.ListBuffer
object FetchRHSTweetsUtil {
// get RHS tweets given LHS users
def fetchRHSTweets(
userIds: Seq[Long],
bipartiteGraph: BipartiteGraph
): Seq[Long] = {
userIds.distinct
.flatMap { userId =>
val tweetIdsIterator = bipartiteGraph
.getLeftNodeEdges(userId).asInstanceOf[MultiSegmentIterator[BipartiteGraphSegment]]
val tweetIds = new ListBuffer[Long]()
if (tweetIdsIterator != null) {
while (tweetIdsIterator.hasNext) {
val rightNode = tweetIdsIterator.nextLong()
tweetIds += rightNode
}
}
tweetIds.distinct
}
}
}