mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-18 17:18:48 +02:00
![twitter-team](/assets/img/avatar_default.png)
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.
36 lines
1.5 KiB
Scala
36 lines
1.5 KiB
Scala
package com.twitter.product_mixer.component_library.selector
|
|
|
|
import com.twitter.product_mixer.core.feature.Feature
|
|
import com.twitter.product_mixer.core.functional_component.common.CandidateScope
|
|
import com.twitter.product_mixer.core.functional_component.selector.Selector
|
|
import com.twitter.product_mixer.core.functional_component.selector.SelectorResult
|
|
import com.twitter.product_mixer.core.model.common.presentation.CandidateWithDetails
|
|
import com.twitter.product_mixer.core.pipeline.PipelineQuery
|
|
|
|
/**
|
|
* A selector that appends all candidates missing a specific feature to the results pool and keeps
|
|
* the rest in the remaining candidates. This is useful for backfill scoring candidates without
|
|
* a score from a previous scorer.
|
|
* @param pipelineScope The pipeline scope to check
|
|
* @param missingFeature The missing feature to check for.
|
|
*/
|
|
case class InsertAppendWithoutFeatureResults(
|
|
override val pipelineScope: CandidateScope,
|
|
missingFeature: Feature[_, _])
|
|
extends Selector[PipelineQuery] {
|
|
|
|
override def apply(
|
|
query: PipelineQuery,
|
|
remainingCandidates: Seq[CandidateWithDetails],
|
|
result: Seq[CandidateWithDetails]
|
|
): SelectorResult = {
|
|
val (candidatesWithMissingFeature, candidatesWithFeature) = remainingCandidates.partition {
|
|
candidate =>
|
|
pipelineScope.contains(candidate) && !candidate.features.getSuccessfulFeatures
|
|
.contains(missingFeature)
|
|
}
|
|
val updatedResults = result ++ candidatesWithMissingFeature
|
|
SelectorResult(remainingCandidates = candidatesWithFeature, result = updatedResults)
|
|
}
|
|
}
|