pub fn filter_scripts(
query: &str,
scripts: &[Script],
search_descriptions: bool,
) -> Vec<(usize, i64)>Expand description
Filter scripts based on a query.
Returns (index, score) pairs sorted by score descending (best matches first). Uses the global pre-compiled matcher for performance.
§Arguments
query- The search query (empty query returns all scripts with score 0)scripts- Slice of scripts to filtersearch_descriptions- Whether to also search in script descriptions
§Returns
Vector of (original_index, score) tuples, sorted by score descending.
§Examples
use npm_run_scripts::package::Script;
use npm_run_scripts::filter::filter_scripts;
let scripts = vec![
Script::new("dev", "vite"),
Script::new("build", "vite build"),
Script::new("test", "vitest"),
];
let results = filter_scripts("dev", &scripts, false);
assert_eq!(results.len(), 1);
assert_eq!(results[0].0, 0); // "dev" is at index 0