Skip to main content

score

Function score 

Source
pub fn score(query: &str, text: &str) -> Option<u32>
Available on crate feature command only.
Expand description

How well query matches text, ignoring case, or None when it does not match. Higher is better, and an empty query matches everything with 0.

An exact match ranks first, then a prefix, then the query at the start of a later word, then anywhere inside a word. Otherwise the letters must appear in order, and runs of letters and word starts score more. Within the first four kinds, shorter texts rank higher.

use iced_cube::navigation::command::score;

assert!(score("set", "Settings") > score("set", "Reset view"));
assert!(score("nf", "New file").is_some());
assert!(score("xyz", "Settings").is_none());