mirror of
https://github.com/xai-org/x-algorithm.git
synced 2026-02-13 03:05:06 +01:00
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
use crate::candidate_pipeline::candidate::PostCandidate;
|
|
use crate::candidate_pipeline::query::ScoredPostsQuery;
|
|
use crate::params as p;
|
|
use tonic::async_trait;
|
|
use xai_candidate_pipeline::scorer::Scorer;
|
|
|
|
// Prioritize in-network candidates over out-of-network candidates
|
|
pub struct OONScorer;
|
|
|
|
#[async_trait]
|
|
impl Scorer<ScoredPostsQuery, PostCandidate> for OONScorer {
|
|
async fn score(
|
|
&self,
|
|
_query: &ScoredPostsQuery,
|
|
candidates: &[PostCandidate],
|
|
) -> Result<Vec<PostCandidate>, String> {
|
|
let scored = candidates
|
|
.iter()
|
|
.map(|c| {
|
|
let updated_score = c.score.map(|base_score| match c.in_network {
|
|
Some(false) => base_score * p::OON_WEIGHT_FACTOR,
|
|
_ => base_score,
|
|
});
|
|
|
|
PostCandidate {
|
|
score: updated_score,
|
|
..Default::default()
|
|
}
|
|
})
|
|
.collect();
|
|
|
|
Ok(scored)
|
|
}
|
|
|
|
fn update(&self, candidate: &mut PostCandidate, scored: PostCandidate) {
|
|
candidate.score = scored.score;
|
|
}
|
|
}
|