Command Palette: a word inside a word combines with the other matches

A query word that is text inside a word of a result now counts as
matched when the other words match through a stem form, a word of the
same meaning, a typo or the description: "bg mov" finds Remove
Background. Before, such a word left the result out unless every word
was text in its names or ids. A word that is text inside some result's
names or ids also keeps the later words compared for typos.
This commit is contained in:
dotCooCoo committed 2026-11-16 09:59:02 -08:00
1 parent 93be92cc21
commit 7c2bb2aff8
1 file changed
+26 -7
+26 -7
View File
@@ -654,6 +654,7 @@ type RankKey = (bool, bool, u8, u8, u32, u8, u8, usize);
/// or starts a word of its label, menu path, description ([`description`]) or id, shares an English
/// stem form with a word of its label, menu path or description ("rounded corners" for Round
/// Corners…) or means the same as a word of its label, menu path or description ("remove bg" for
/// Remove Background…), where a word may also be text in one of its names or ids ("bg mov" for
/// Remove Background…), or when the query is the initials of a label ("ea" for Export As…). A query
/// word that is no word, stem form or word start of any result's label, menu path or id also
/// matches the words of labels and menu paths it is a typo of ([`Index::typos`]).
@@ -680,9 +681,9 @@ pub(crate) fn rank(entries: &[Entry], index: &Index, query: &str) -> Vec<u32> {
let mut indexed: Vec<Vec<u8>> = Vec::with_capacity(tokens.len());
let mut typos: Vec<Vec<usize>> = Vec::with_capacity(tokens.len());
let mut meanings: Vec<Vec<usize>> = Vec::with_capacity(tokens.len());
// After a word that is nothing in any result and a typo of nothing, a result is found only by
// the substring rule or its initials, where a typo grade changes nothing, so the later words are
// not compared.
// After a word that is nothing in any result, a typo of nothing and text inside no result's names
// or ids, a result is found only by its initials, where a typo grade changes nothing, so the later
// words are not compared.
let mut compare = true;
for (k, t) in tokens.iter().enumerate() {
// A repeated word is graded once.
@@ -699,7 +700,7 @@ pub(crate) fn rank(entries: &[Entry], index: &Index, query: &str) -> Vec<u32> {
// A word that matches only words of descriptions is still compared with the words of labels
// and menu paths it may be a typo of.
let near = if compare && grades.iter().all(|&g| g == NONE || g == DESCRIPTION_WORD) { index.typos(t) } else { vec![] };
if near.is_empty() && grades.iter().all(|&g| g == NONE) {
if near.is_empty() && grades.iter().all(|&g| g == NONE) && !entries.iter().any(|e| e.haystack.contains(t)) {
compare = false;
}
index.mark_typos(&near, &mut grades);
@@ -736,12 +737,15 @@ pub(crate) fn rank(entries: &[Entry], index: &Index, query: &str) -> Vec<u32> {
};
for (k, (grades, token)) in indexed.iter().zip(&tokens).enumerate() {
let mut g = grades.get(i).copied().unwrap_or(NONE);
if g == NONE {
all_indexed = false;
}
if g > SUBSTRING && e.haystack.contains(token) {
g = SUBSTRING;
}
// A word that is text inside a word of the result counts as matched, so it combines
// with words matched through a stem form, a word of the same meaning, a typo or the
// description.
if g == NONE {
all_indexed = false;
}
let g = if initials {
g.min(LABEL_PREFIX)
} else if g == NONE {
@@ -1215,6 +1219,21 @@ mod tests {
assert_eq!(ranked(&c, "colour"), ["c.three", "panel:color", "tool:zz"]);
}
/// A word that is text inside a word of the result combines with a word matched through a word
/// of the same meaning, a stem form, a typo or the description, and a word that is text inside
/// a word of no result finds nothing.
#[test]
fn a_word_inside_a_word_combines_with_the_other_matches() {
let c = described(vec![entry("Remove Background…", "a.one"), entry("Zz Group", "b.two")], &["{} make the images transparent", ""]);
assert_eq!(ranked(&c, "bg remove"), ["a.one"]);
assert_eq!(ranked(&c, "background mov"), ["a.one"]);
assert_eq!(ranked(&c, "bg mov"), ["a.one"], "a word of the same meaning");
assert_eq!(ranked(&c, "removing kgrou"), ["a.one"], "a stem form");
assert_eq!(ranked(&c, "transparent kgrou"), ["a.one"], "the description");
assert_eq!(ranked(&c, "emov backgruond"), ["a.one"], "a typo after a word inside a word");
assert!(ranked(&c, "bg qxq").is_empty());
}
/// A catalog row adds words in the UI language to a group, and a word that is not a single word
/// or that is a word of another group is left out.
#[test]