feat(config): add search terms option. #789 #796

This commit is contained in:
Federico Terzi 2022-01-04 21:18:17 +01:00
parent 90be91d1e9
commit b31617a2f3
3 changed files with 23 additions and 0 deletions

View File

@ -300,6 +300,7 @@ pub fn try_convert_into_match(
effect, effect,
label: yaml_match.label, label: yaml_match.label,
id: next_id(), id: next_id(),
search_terms: yaml_match.search_terms.unwrap_or_default(),
}, },
warnings, warnings,
)) ))

View File

@ -114,6 +114,9 @@ pub struct YAMLMatch {
#[serde(default)] #[serde(default)]
pub html: Option<String>, pub html: Option<String>,
#[serde(default)]
pub search_terms: Option<Vec<String>>,
} }
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]

View File

@ -35,6 +35,7 @@ pub struct Match {
// Metadata // Metadata
pub label: Option<String>, pub label: Option<String>,
pub search_terms: Vec<String>,
} }
impl Default for Match { impl Default for Match {
@ -44,6 +45,7 @@ impl Default for Match {
effect: MatchEffect::None, effect: MatchEffect::None,
label: None, label: None,
id: 0, id: 0,
search_terms: vec![],
} }
} }
} }
@ -66,6 +68,15 @@ impl Match {
pub fn cause_description(&self) -> Option<&str> { pub fn cause_description(&self) -> Option<&str> {
self.cause.description() self.cause.description()
} }
pub fn search_terms(&self) -> Vec<&str> {
self
.search_terms
.iter()
.map(|term| term.as_str())
.chain(self.cause.search_terms())
.collect()
}
} }
// Causes // Causes
@ -100,6 +111,14 @@ impl MatchCause {
// TODO: insert rendering for hotkey/shortcut // TODO: insert rendering for hotkey/shortcut
// TODO: insert rendering for regex? I'm worried it might be too long // TODO: insert rendering for regex? I'm worried it might be too long
} }
pub fn search_terms(&self) -> Vec<&str> {
if let MatchCause::Trigger(trigger_cause) = &self {
trigger_cause.triggers.iter().map(|s| s.as_str()).collect()
} else {
vec![]
}
}
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]