MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / fuzzy_match

Function fuzzy_match

crates/opencode-tui/src/command.rs:7–19  ·  view source on GitHub ↗
(query: &str, target: &str)

Source from the content-addressed store, hash-verified

5use nucleo_matcher::{Config, Matcher, Utf32Str};
6
7pub fn fuzzy_match(query: &str, target: &str) -> Option<i32> {
8 let trimmed = query.trim();
9 if trimmed.is_empty() {
10 return Some(0);
11 }
12
13 let pattern = Pattern::parse(trimmed, CaseMatching::Ignore, Normalization::Smart);
14 let mut matcher = Matcher::new(Config::DEFAULT);
15 let mut utf32_buf = Vec::new();
16 pattern
17 .score(Utf32Str::new(target, &mut utf32_buf), &mut matcher)
18 .map(|score| score.min(i32::MAX as u32) as i32)
19}
20
21#[derive(Clone, Debug, PartialEq, Eq, Hash)]
22pub enum CommandCategory {

Callers 3

searchMethod · 0.70
push_candidateMethod · 0.50
filter_commandsMethod · 0.50

Calls 2

newFunction · 0.85
is_emptyMethod · 0.80

Tested by

no test coverage detected