use crate::index::IndexError;
const DELIMITER: char = '\u{1f}';
const ESCAPE: char = '\u{1e}';
#[must_use]
pub fn facet_field_name(property_name: &str) -> String {
format!("{property_name}_facet")
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FacetValue {
pub dimension: String,
pub label: String,
}
impl FacetValue {
pub fn to_path(&self, definition_path: &str) -> Result<String, IndexError> {
let mut rendered = String::new();
for component in [&self.dimension, &self.label] {
if component.is_empty() {
return Err(IndexError::UnsupportedDefinition {
definition_path: definition_path.to_owned(),
feature: "a facet path component is empty, which Lucene's own facet \
configuration refuses"
.to_owned(),
});
}
for character in component.chars() {
if character == DELIMITER || character == ESCAPE {
rendered.push(ESCAPE);
}
rendered.push(character);
}
rendered.push(DELIMITER);
}
rendered.pop();
Ok(rendered)
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FacetDimension {
pub name: String,
pub multi_valued: bool,
}