#fuzzy-search #search #fuzzy-matching #bitap #weighted-search

fuse-rust

Fuse is a super lightweight library which provides a simple way to do fuzzy searching. Fuse-Rust is a port of Fuse-Swift, written purely in rust

10 releases

0.4.0 Oct 18, 2024
0.3.2 Oct 2, 2023
0.3.1 Dec 8, 2022
0.3.0 Aug 29, 2021
0.1.2 Oct 6, 2020

#279 in Algorithms

Download history 8/week @ 2024-08-26 7/week @ 2024-09-02 5/week @ 2024-09-09 66/week @ 2024-09-23 7/week @ 2024-09-30 13/week @ 2024-10-07 390/week @ 2024-10-14 261/week @ 2024-10-21 222/week @ 2024-10-28 258/week @ 2024-11-04 201/week @ 2024-11-11 186/week @ 2024-11-18 254/week @ 2024-11-25 321/week @ 2024-12-02

989 downloads per month
Used in 3 crates

MIT license

1.5MB
642 lines

Fuse-rust

What is Fuse?

Fuse is a super lightweight library which provides a simple way to do fuzzy searching.

Fuse-RS is a port of https://github.com/krisk/fuse-swift written purely in rust.

Usage

An example of a real use case, a search bar made using iced is also available.

Try it using

cargo run --package search_bar

Check all available examples and their source code here.

Async

Use the feature flag "async" to also be able to use async functions.

fuse-rust = { version = ..., features = ["async"]}

Initializing

The first step is to create a fuse object, with the necessary parameters. Fuse::default, returns the following parameters.

Fuse::default() = Fuse{
    location: 0, // Approx where to start looking for the pattern
    distance: 100, // Maximum distance the score should scale to
    threshold: 0.6, // A threshold for guess work
    max_pattern_length: 32, // max valid pattern length
    is_case_sensitive: false,
    tokenize: false, // the input search text should be tokenized
}

For how to implement individual searching operations, check the examples.

Options

As given above, Fuse takes the following options

  • location: Approximately where in the text is the pattern expected to be found. Defaults to 0
  • distance: Determines how close the match must be to the fuzzy location (specified above). An exact letter match which is distance characters away from the fuzzy location would score as a complete mismatch. A distance of 0 requires the match be at the exact location specified, a distance of 1000 would require a perfect match to be within 800 characters of the fuzzy location to be found using a 0.8 threshold. Defaults to 100
  • threshold: At what point does the match algorithm give up. A threshold of 0.0 requires a perfect match (of both letters and location), a threshold of 1.0 would match anything. Defaults to 0.6
  • maxPatternLength: The maximum valid pattern length. The longer the pattern, the more intensive the search operation will be. If the pattern exceeds the maxPatternLength, the search operation will return nil. Why is this important? Read this. Defaults to 32
  • isCaseSensitive: Indicates whether comparisons should be case sensitive. Defaults to false

Dependencies