#[derive(Debug, Clone, PartialEq)]
pub enum FtsQuery {
Plain { text: String, fuzzy: bool },
And(Vec<FtsQuery>),
Or(Vec<FtsQuery>),
Not(Box<FtsQuery>),
Phrase(Vec<String>),
Prefix(String),
}
impl FtsQuery {
pub fn as_plain_text(&self) -> Option<&str> {
match self {
FtsQuery::Plain { text, .. } => Some(text.as_str()),
_ => None,
}
}
pub fn is_fuzzy(&self) -> bool {
match self {
FtsQuery::Plain { fuzzy, .. } => *fuzzy,
_ => false,
}
}
pub fn to_plain_string(&self) -> Option<String> {
match self {
FtsQuery::Plain { text, .. } => Some(text.clone()),
FtsQuery::And(terms) | FtsQuery::Or(terms) => {
let parts: Option<Vec<String>> =
terms.iter().map(|t| t.to_plain_string()).collect();
parts.map(|p| p.join(" "))
}
FtsQuery::Prefix(p) => Some(p.clone()),
FtsQuery::Not(_) | FtsQuery::Phrase(_) => None,
}
}
}