Library

Search

Register the algorithms you want, hand it a dataset, and decide what order they run in and what happens when one hits. Registering an algorithm widens the pipeline's type, so an unregistered name in the run order is a compile error rather than a silent no-op.

npm install @michaelrwalker/search
  • naive exact
  • kmp substring
  • levenshtein fuzzy
  • soundex phonetic
MacBook Pro 16" 0.93
MacBook Pro 14" 0.81

// reference

One pipeline, hover to learn it

Every highlighted token is real Search API — hover or tab to it to watch the registered-name type widen with each .register().

finder.ts hover the highlighted tokens

				
				import { KMP, Levenshtein, NaiveSearch, Search } from "@michaelrwalker/search";
			
				
				 
			
				
				const finder = new Search()
			
				
				.register(NaiveSearch())
			
				
				.register(KMP(), { stopOnMatch: true })
			
				
				.register(Levenshtein({ threshold: 0.8 }), { limit: 5 })
			
				
				.defineDataset(models)
			
				
				.runOrder(["naive", "kmp", "levenshtein"])
			
				
				.defineBehavior("find-all")
			
				
				.cullMatchedRows();
			
				
				 
			
				
				const result = finder.search("MacBook Pr 16");
			
				
				 
			
				
				result.matched;
			
				
				// true — something in the dataset was close enough
			
				
				 
			
				
				result.best;
			
				
				// SearchMatch | null — highest confidence across every algorithm
			
				
				 
			
				
				result.matches;
			
				
				// SearchMatch[] — every match, in run order then dataset order
			
				
				 
			
				
				result.ranAlgorithms;
			
				
				// string[] — shorter than runOrder when a stopOnMatch algorithm ends it early
			

Contents 15 pages