fuzzysearch

repository·master·Indexed 23 days ago

https://github.com/lithammer/fuzzysearch

A Go library for fuzzy string matching that supports pattern matching, ranking via Levenshtein distance, and searching through lists of words. It includes functions for basic matching, ranking, and specialized Unicode normalized or case-insensitive matching.

Tokens
716
Snippets
5
Records
6
Agent score
30%

What's inside fuzzysearch

  1. Rank matches using RankMatch

    master

    Use fuzzy.RankMatch(pattern, target) to get a ranking score for a match based on Levenshtein distance. It returns a score (integer) representing the quality of the match, or -1 if no match is found.

    import "github.com/lithammer/fuzzysearch/fuzzy"
    
    // Returns a score for the match
    fuzzy.RankMatch("cart", "cartwheel") // 5
    fuzzy.RankMatch("kitten", "sitting") // -1
  2. Find and rank matches in a list with RankFind

    master
    Use fuzzy.RankFind(pattern, words) to search through a slice of strings and return detailed match information. Each result includes the pattern, the matched word, a score, and an index. The results can be sorted using the standard library sort package.
  3. Use Unicode normalized and case-insensitive matching

    master

    The library provides specialized matching functions for specific requirements:

    • fuzzy.MatchNormalized(target, pattern): Performs matching using Unicode normalization (e.g., matching 'e' with 'é').
    • fuzzy.MatchFold(pattern, target): Performs case-insensitive matching using Unicode folding.
    import "github.com/lithammer/fuzzysearch/fuzzy"
    
    // Unicode normalized matching
    fuzzy.MatchNormalized("cartwheel", "cartwhéél") // true
    
    // Case insensitive matching
    fuzzy.MatchFold("ArTeeL", "cartwheel") // true
  4. Find matches in a list of words with Find

    master

    Use fuzzy.Find(pattern, words) to search through a slice of strings. It returns a slice of strings containing only the words that match the pattern.

    import "github.com/lithammer/fuzzysearch/fuzzy"
    
    words := []string{"cartwheel", "foobar", "wheel", "baz"}
    matches := fuzzy.Find("whl", words) // []string{"cartwheel", "wheel"}
  5. Perform basic fuzzy matching with Match

    master

    Use fuzzy.Match(pattern, target) to check if a pattern exists within a target string. It returns true if the pattern can be found in the target string by skipping characters, and false otherwise.

    import "github.com/lithammer/fuzzysearch/fuzzy"
    
    // Returns true if the pattern matches
    fuzzy.Match("twl", "cartwheel")  // true
    fuzzy.Match("eeel", "cartwheel") // false