From f18c19cd53668cefad118358e63ab0fc5131e37f Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Mon, 21 Aug 2023 01:02:53 +0200 Subject: [PATCH] fix sort order of literal matcher (#13) --- Cargo.toml | 2 +- src/lib.rs | 2 +- src/pattern.rs | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a9732a..43e6806 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "nucleo" description = "plug and play high performance fuzzy matcher" authors = ["Pascal Kuthe "] -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/helix-editor/nucleo" diff --git a/src/lib.rs b/src/lib.rs index 9d2725d..59386bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -345,6 +345,6 @@ pub fn fuzzy_match>( .map(|score| (item, score)) }) .collect(); - items.sort_by_key(|(item, score)| (Reverse(*score), item.as_ref().len())); + items.sort_by_key(|(_, score)| Reverse(*score)); items } diff --git a/src/pattern.rs b/src/pattern.rs index 9475a13..f9939c6 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -373,7 +373,9 @@ impl Pattern { self.atoms.clear(); let pattern = PatternAtom::literal(pattern, self.normalize, self.case_matching, kind, false); - self.atoms.push(pattern); + if !pattern.needle.is_empty() { + self.atoms.push(pattern); + } self.status = if append && self.status != Status::Rescore { Status::Update } else {