feat: changed applications matching/weighting (#88)
This commit is contained in:
@@ -105,13 +105,25 @@ pub fn get_matches(input: RString, state: &State) -> RVec<Match> {
|
||||
.entries
|
||||
.iter()
|
||||
.filter_map(|(entry, id)| {
|
||||
let score: i64 = matcher.fuzzy_match(&entry.name, &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>();
|
||||
let app_score = match &entry.desc {
|
||||
None => matcher.fuzzy_match(&entry.name, &input).unwrap_or(0),
|
||||
Some(val) => matcher
|
||||
.fuzzy_match(&format!("{} {}", &val, &entry.name).to_string(), &input)
|
||||
.unwrap_or(0),
|
||||
};
|
||||
|
||||
let keyword_score = entry
|
||||
.keywords
|
||||
.iter()
|
||||
.map(|keyword| matcher.fuzzy_match(keyword, &input).unwrap_or(0))
|
||||
.sum::<i64>();
|
||||
|
||||
let mut score = (app_score * 25 + keyword_score) - entry.offset;
|
||||
|
||||
// prioritize actions
|
||||
if entry.desc.is_some() {
|
||||
score = score * 2;
|
||||
}
|
||||
|
||||
if score > 0 {
|
||||
Some((entry, *id, score))
|
||||
|
@@ -11,6 +11,7 @@ pub struct DesktopEntry {
|
||||
pub desc: Option<String>,
|
||||
pub icon: String,
|
||||
pub term: bool,
|
||||
pub offset: i64,
|
||||
}
|
||||
|
||||
const FIELD_CODE_LIST: &[&str] = &[
|
||||
@@ -95,6 +96,7 @@ impl DesktopEntry {
|
||||
.get("Terminal")
|
||||
.map(|val| val.to_lowercase() == "true")
|
||||
.unwrap_or(false),
|
||||
offset: 0,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
@@ -108,7 +110,7 @@ impl DesktopEntry {
|
||||
};
|
||||
|
||||
if config.desktop_actions {
|
||||
for section in new_sections {
|
||||
for (i, section) in new_sections.iter().enumerate() {
|
||||
let mut map = HashMap::new();
|
||||
|
||||
for line in section.iter().skip(1) {
|
||||
@@ -150,6 +152,7 @@ impl DesktopEntry {
|
||||
.get("Terminal")
|
||||
.map(|val| val.to_lowercase() == "true")
|
||||
.unwrap_or(false),
|
||||
offset: i as i64,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user