Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Now time.Time
Now is point of reference Score.Update and Score.Relevance use to reference the current time. It is used in testing, so we always have the same current time. This is okay for this program as it won't run for long.
Functions ¶
This section is empty.
Types ¶
type Entries ¶
type Entries []*Entry
Entries represents entries slice that supports sort.Interface.
func (Entries) Find ¶
Find finds an entry by a given path.
If the entry isn't found, (nil, false) is returned.
func (Entries) Less ¶
Less compares two indexes in the entries and returns true if the value at i is less than the value at j.
type Entry ¶
Entry represents a path and a score.
func NewEntry ¶
NewEntry creates a new entry with the specified path. The score is created with NewScore.
func (*Entry) CalculateScore ¶
CalculateScore calculates the score for an entry.
func (*Entry) UpdateScore ¶
UpdateScore updates the score for an entry.
type FuzzyEntries ¶
FuzzyEntries represents entries slice that supports sort.Interface which can be sorted by a fuzzy search term.
func NewFuzzyEntries ¶
func NewFuzzyEntries(entries Entries, target string) *FuzzyEntries
NewFuzzyEntries converts a FuzzyEntries and a target string to a FuzzyEntries struct.
Entries is expected to be sorted in ASC before creating the FuzzyEntries. This gives us the best match. This is not enforced, however.
func (*FuzzyEntries) Less ¶
func (fe *FuzzyEntries) Less(i, j int) bool
Less compares the Longest Subsequence Length between the term string and every entry. The entries with greater LCS come first.
type Score ¶
Score represents a weight of a score and the age of it.
func NewScore ¶
func NewScore() *Score
NewScore creates a new score object with default weight of 1 and age set to now.
func (*Score) Relevance ¶
Relevance of a score is the quotient of the score age and the current time.
It is expected to be between 1 and 2. Can be more, though, if the age of the score is in the future.