use nodedb_physical::physical_plan::RegisteredIndexState;
#[derive(Debug, Clone)]
pub struct IndexPath {
pub name: String,
pub path: String,
pub is_array: bool,
pub unique: bool,
pub case_insensitive: bool,
pub state: RegisteredIndexState,
pub predicate: Option<crate::engine::document::predicate::IndexPredicate>,
}
impl IndexPath {
pub fn new(path: &str) -> Self {
let is_array = path.ends_with("[]");
let path_trimmed = path.strip_suffix("[]").unwrap_or(path).to_string();
Self {
name: path_trimmed.clone(),
path: path_trimmed,
is_array,
unique: false,
case_insensitive: false,
state: RegisteredIndexState::Ready,
predicate: None,
}
}
pub fn from_registered(spec: &nodedb_physical::physical_plan::RegisteredIndex) -> Self {
let is_array = spec.path.ends_with("[]");
let path = spec
.path
.strip_suffix("[]")
.unwrap_or(&spec.path)
.to_string();
let predicate = spec
.predicate
.as_deref()
.and_then(crate::engine::document::predicate::IndexPredicate::parse);
Self {
name: spec.name.clone(),
path,
is_array,
unique: spec.unique,
case_insensitive: spec.case_insensitive,
state: spec.state,
predicate,
}
}
}