fuzzymatcher

package module
v1.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 1 Imported by: 2

README

fuzzy-matcher

A fast golang fuzzy string matcher

// New matcher creates a new matcher to be used for matching
// Note that this operation takes the most time
matcher := fuzzymatcher.NewMatcher(
    "I love trees",
    "bananas are the best fruit",
    "peer",
)

// match returns the best match for the given string or -1 if no match was found
fmt.Println(matcher.Match("do i love the trees") == 0)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher struct {
	Sentences []sentenceT

	// the fields below are generated with the (*Matcher).complete() method
	Paths                []pathToWord
	HasPathsWithRuneSelf bool                        // basicly tells if there are complex utf8 chars
	PathByLetterMap      map[rune][]pathToWord       // Use if HasPathsWithRuneSelf == true
	PathByLetterList     [utf8.RuneSelf][]pathToWord // Use if HasPathsWithRuneSelf == false

	// Zero alloc cache
	UTF8RuneCreation  []byte
	InProgressMatches []inProgressMatch
}

Matcher is used to match sentences

func NewMatcher

func NewMatcher(sentences ...string) *Matcher

NewMatcher creates a new instance of the matcher This function takes relatively long to execute so do this once, and use the returned matcher to match it against lots of entries

func (*Matcher) Match

func (m *Matcher) Match(sentence string) int

Match matches a sentence to the matchers input Returns the index of the matched sentenced If nothing found returns -1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL