feat(modulo): implement additional search items. #789
This commit is contained in:
parent
35ed59bd23
commit
90be91d1e9
|
@ -44,7 +44,9 @@ fn exact_match(query: &str, items: &[SearchItem]) -> Vec<usize> {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, item)| {
|
||||
item.label.contains(query) || item.trigger.as_deref().map_or(false, |t| t.contains(query))
|
||||
item.label.contains(query)
|
||||
|| item.trigger.as_deref().map_or(false, |t| t.contains(query))
|
||||
|| item.search_terms.iter().any(|term| term.contains(query))
|
||||
})
|
||||
.map(|(i, _)| i)
|
||||
.collect()
|
||||
|
@ -61,6 +63,10 @@ fn case_insensitive_exact_match(query: &str, items: &[SearchItem]) -> Vec<usize>
|
|||
.trigger
|
||||
.as_deref()
|
||||
.map_or(false, |t| t.to_lowercase().contains(query))
|
||||
|| item
|
||||
.search_terms
|
||||
.iter()
|
||||
.any(|term| term.to_lowercase().contains(&lowercase_query))
|
||||
})
|
||||
.map(|(i, _)| i)
|
||||
.collect()
|
||||
|
@ -79,6 +85,10 @@ fn case_insensitive_keyword(query: &str, items: &[SearchItem]) -> Vec<usize> {
|
|||
.trigger
|
||||
.as_deref()
|
||||
.map_or(false, |t| t.to_lowercase().contains(keyword))
|
||||
&& !item
|
||||
.search_terms
|
||||
.iter()
|
||||
.any(|term| term.to_lowercase().contains(keyword))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ pub struct SearchItem {
|
|||
pub id: String,
|
||||
pub label: String,
|
||||
pub trigger: Option<String>,
|
||||
pub search_terms: Vec<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub is_builtin: bool,
|
||||
|
|
|
@ -28,6 +28,7 @@ pub fn generate(config: SearchConfig) -> types::Search {
|
|||
id: item.id,
|
||||
label: item.label,
|
||||
trigger: item.trigger,
|
||||
search_terms: item.search_terms,
|
||||
is_builtin: item.is_builtin,
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -26,6 +26,7 @@ pub mod types {
|
|||
pub id: String,
|
||||
pub label: String,
|
||||
pub trigger: Option<String>,
|
||||
pub search_terms: Vec<String>,
|
||||
pub is_builtin: bool,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user