use crate::domain::IndexKind;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IndexRefreshPlan {
kinds: Vec<IndexKind>,
}
impl IndexRefreshPlan {
pub fn from_requested(kinds: Vec<IndexKind>) -> Self {
if kinds.is_empty() {
return Self {
kinds: IndexKind::ALL.to_vec(),
};
}
let mut deduped = Vec::new();
for kind in kinds {
if !deduped.contains(&kind) {
deduped.push(kind);
}
}
Self { kinds: deduped }
}
pub fn into_kinds(self) -> Vec<IndexKind> {
self.kinds
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_request_refreshes_all_index_families() {
let plan = IndexRefreshPlan::from_requested(Vec::new());
assert_eq!(plan.into_kinds(), IndexKind::ALL);
}
#[test]
fn duplicate_index_kinds_are_removed_in_order() {
let plan = IndexRefreshPlan::from_requested(vec![
IndexKind::Vector,
IndexKind::Vector,
IndexKind::Bm25,
]);
assert_eq!(plan.into_kinds(), [IndexKind::Vector, IndexKind::Bm25]);
}
}