starfuzz/search
A module providing fuzzy search collections matching capabilities. Collections of custom candidates can be searched in-memory with custom selectors, similarity scoring functions, score thresholds, and limits.
Types
A matched result from a fuzzy search query.
pub type Match(candidate) {
Match(candidate: candidate, score: Float, index: Int)
}
Constructors
-
Match(candidate: candidate, score: Float, index: Int)Arguments
- candidate
-
The original candidate item from the list.
- score
-
The similarity score calculated for this match (between 0.0 and 1.0).
- index
-
The original index of this candidate in the input list (used for stable tie-breaking).
An immutable search configuration builder.
pub type SearchBuilder(candidate) {
SearchBuilder(
candidates: List(candidate),
selector: fn(candidate) -> String,
scorer: fn(String, String) -> Float,
normalizer: option.Option(normalize.Normalizer),
min_score: Float,
limit: option.Option(Int),
)
}
Constructors
-
SearchBuilder( candidates: List(candidate), selector: fn(candidate) -> String, scorer: fn(String, String) -> Float, normalizer: option.Option(normalize.Normalizer), min_score: Float, limit: option.Option(Int), )
Values
pub fn by(
builder: SearchBuilder(candidate),
selector: fn(candidate) -> String,
) -> SearchBuilder(candidate)
Configures a custom selector function to retrieve the string value to match from candidates.
pub fn new(
candidates: List(candidate),
selector: fn(candidate) -> String,
) -> SearchBuilder(candidate)
Creates a new SearchBuilder with the list of candidates and a string selector function. Defaults to using Levenshtein similarity, no normalizer, minimum score of 0.0, and no limit.
pub fn run(
builder: SearchBuilder(candidate),
query: String,
) -> List(Match(candidate))
Runs the fuzzy search query against the candidates list. Returns matched candidates sorted descending by score, with original index-based tie-breaking.
pub fn strings(
query: String,
candidates: List(String),
) -> List(Match(String))
Quick direct search over a list of strings using default Levenshtein similarity.
pub fn using(
builder: SearchBuilder(candidate),
scorer: fn(String, String) -> Float,
) -> SearchBuilder(candidate)
Configures the similarity scoring function to use for comparison (e.g. similarity.jaro_winkler).
pub fn with_limit(
builder: SearchBuilder(candidate),
limit: Int,
) -> SearchBuilder(candidate)
Configures a limit on the number of matches returned.
pub fn with_minimum_score(
builder: SearchBuilder(candidate),
min_score: Float,
) -> SearchBuilder(candidate)
Configures the minimum score threshold. Matches below this score are discarded.
pub fn with_normalizer(
builder: SearchBuilder(candidate),
normalizer: normalize.Normalizer,
) -> SearchBuilder(candidate)
Configures the normalizer to clean up both query and candidate strings before scoring.