feat: changed applications matching/weighting (#88)

This commit is contained in:
Andrej Benz
2023-08-19 16:52:53 +02:00
committed by GitHub
parent ca77298d46
commit cebc052f0d
2 changed files with 23 additions and 8 deletions

View File

@@ -105,14 +105,26 @@ pub fn get_matches(input: RString, state: &State) -> RVec<Match> {
.entries .entries
.iter() .iter()
.filter_map(|(entry, id)| { .filter_map(|(entry, id)| {
let score: i64 = matcher.fuzzy_match(&entry.name, &input).unwrap_or(0) let app_score = match &entry.desc {
+ matcher.fuzzy_match(&entry.exec, &input).unwrap_or(0) None => matcher.fuzzy_match(&entry.name, &input).unwrap_or(0),
+ entry Some(val) => matcher
.fuzzy_match(&format!("{} {}", &val, &entry.name).to_string(), &input)
.unwrap_or(0),
};
let keyword_score = entry
.keywords .keywords
.iter() .iter()
.map(|keyword| matcher.fuzzy_match(keyword, &input).unwrap_or(0)) .map(|keyword| matcher.fuzzy_match(keyword, &input).unwrap_or(0))
.sum::<i64>(); .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 { if score > 0 {
Some((entry, *id, score)) Some((entry, *id, score))
} else { } else {

View File

@@ -11,6 +11,7 @@ pub struct DesktopEntry {
pub desc: Option<String>, pub desc: Option<String>,
pub icon: String, pub icon: String,
pub term: bool, pub term: bool,
pub offset: i64,
} }
const FIELD_CODE_LIST: &[&str] = &[ const FIELD_CODE_LIST: &[&str] = &[
@@ -95,6 +96,7 @@ impl DesktopEntry {
.get("Terminal") .get("Terminal")
.map(|val| val.to_lowercase() == "true") .map(|val| val.to_lowercase() == "true")
.unwrap_or(false), .unwrap_or(false),
offset: 0,
}) })
} else { } else {
None None
@@ -108,7 +110,7 @@ impl DesktopEntry {
}; };
if config.desktop_actions { if config.desktop_actions {
for section in new_sections { for (i, section) in new_sections.iter().enumerate() {
let mut map = HashMap::new(); let mut map = HashMap::new();
for line in section.iter().skip(1) { for line in section.iter().skip(1) {
@@ -150,6 +152,7 @@ impl DesktopEntry {
.get("Terminal") .get("Terminal")
.map(|val| val.to_lowercase() == "true") .map(|val| val.to_lowercase() == "true")
.unwrap_or(false), .unwrap_or(false),
offset: i as i64,
}) })
} }
} }