use anyhow::Result;
use rusqlite::Connection;
use crate::retrieval::search::common::distinct_hit_ids;
use crate::retrieval::search::usage_hits_for_retrieved_candidates;
use crate::retrieval::search::SearchWeights;
use super::ContextChannel;
pub(super) fn push_usage_channel(
conn: &Connection,
channels: &mut Vec<ContextChannel>,
weights: SearchWeights,
) -> Result<()> {
if weights.usage <= 0.0 {
return Ok(());
}
let candidate_ids = distinct_hit_ids(channels.iter().flat_map(|channel| channel.hits.iter()));
let hits = usage_hits_for_retrieved_candidates(conn, &candidate_ids, weights)?;
if !hits.is_empty() {
channels.push(ContextChannel {
weight: weights.usage,
hits,
});
}
Ok(())
}