Added keyword search
This commit is contained in:
@@ -105,8 +105,13 @@ pub fn get_matches(input: RString, state: &State) -> RVec<Match> {
|
|||||||
.entries
|
.entries
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(entry, id)| {
|
.filter_map(|(entry, id)| {
|
||||||
let score = matcher.fuzzy_match(&entry.name, &input).unwrap_or(0)
|
let score: i64 = matcher.fuzzy_match(&entry.name, &input).unwrap_or(0)
|
||||||
+ matcher.fuzzy_match(&entry.exec, &input).unwrap_or(0);
|
+ matcher.fuzzy_match(&entry.exec, &input).unwrap_or(0)
|
||||||
|
+ entry
|
||||||
|
.keywords
|
||||||
|
.iter()
|
||||||
|
.map(|keyword| matcher.fuzzy_match(keyword, &input).unwrap_or(0))
|
||||||
|
.sum::<i64>();
|
||||||
|
|
||||||
if score > 0 {
|
if score > 0 {
|
||||||
Some((entry, *id, score))
|
Some((entry, *id, score))
|
||||||
|
@@ -7,6 +7,7 @@ pub struct DesktopEntry {
|
|||||||
pub exec: String,
|
pub exec: String,
|
||||||
pub path: Option<PathBuf>,
|
pub path: Option<PathBuf>,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub keywords: Vec<String>,
|
||||||
pub desc: Option<String>,
|
pub desc: Option<String>,
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub term: bool,
|
pub term: bool,
|
||||||
@@ -76,6 +77,15 @@ impl DesktopEntry {
|
|||||||
},
|
},
|
||||||
path: map.get("Path").map(PathBuf::from),
|
path: map.get("Path").map(PathBuf::from),
|
||||||
name: map.get("Name")?.to_string(),
|
name: map.get("Name")?.to_string(),
|
||||||
|
keywords: map
|
||||||
|
.get("Keywords")
|
||||||
|
.map(|keywords| {
|
||||||
|
keywords
|
||||||
|
.split(';')
|
||||||
|
.map(|s| s.to_owned())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
|
.unwrap_or_default(),
|
||||||
desc: None,
|
desc: None,
|
||||||
icon: map
|
icon: map
|
||||||
.get("Icon")
|
.get("Icon")
|
||||||
@@ -125,6 +135,15 @@ impl DesktopEntry {
|
|||||||
Some(name) => name.to_string(),
|
Some(name) => name.to_string(),
|
||||||
None => continue,
|
None => continue,
|
||||||
},
|
},
|
||||||
|
keywords: map
|
||||||
|
.get("Keywords")
|
||||||
|
.map(|keywords| {
|
||||||
|
keywords
|
||||||
|
.split(';')
|
||||||
|
.map(|s| s.to_owned())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
|
.unwrap_or_default(),
|
||||||
desc: Some(entry.name.clone()),
|
desc: Some(entry.name.clone()),
|
||||||
icon: entry.icon.clone(),
|
icon: entry.icon.clone(),
|
||||||
term: map
|
term: map
|
||||||
|
Reference in New Issue
Block a user