#[cfg(test)]
use crate::model::index::IndexModel;
use crate::{
db::access::{SemanticIndexKeyItemRef, SemanticIndexKeyItemsRef},
model::index::{IndexKeyItem, IndexKeyItemsRef},
};
#[must_use]
#[cfg(test)]
pub(in crate::db) fn index_order_terms(index: &IndexModel) -> Vec<String> {
index_key_item_order_terms(SemanticIndexKeyItemsRef::Static(index.key_items()))
}
#[must_use]
pub(in crate::db) fn index_key_item_order_terms(
key_items: SemanticIndexKeyItemsRef<'_>,
) -> Vec<String> {
match key_items {
SemanticIndexKeyItemsRef::Fields(fields) => fields.to_vec(),
SemanticIndexKeyItemsRef::Static(IndexKeyItemsRef::Fields(fields)) => {
canonical_index_order_terms(
fields
.iter()
.copied()
.map(IndexKeyItem::Field)
.map(SemanticIndexKeyItemRef::from),
)
}
SemanticIndexKeyItemsRef::Static(IndexKeyItemsRef::Items(items)) => {
canonical_index_order_terms(items.iter().copied().map(SemanticIndexKeyItemRef::from))
}
}
}
fn canonical_index_order_terms<I>(key_items: I) -> Vec<String>
where
I: IntoIterator<Item = SemanticIndexKeyItemRef<'static>>,
{
key_items
.into_iter()
.map(SemanticIndexKeyItemRef::canonical_text)
.collect()
}