scoring

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

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

func (e Entries) Find(path string) (*Entry, bool)

Find finds an entry by a given path.

If the entry isn't found, (nil, false) is returned.

func (Entries) Len

func (e Entries) Len() int

Len returns the length of the entries slice.

func (Entries) Less

func (e Entries) Less(i, j int) bool

Less compares two indexes in the entries and returns true if the value at i is less than the value at j.

func (*Entries) Remove added in v0.5.0

func (e *Entries) Remove(path string) bool

Remove an entry by its path.

func (*Entries) Sort

func (e *Entries) Sort()

Sort sorts the entries collection.

func (Entries) Swap

func (e Entries) Swap(i, j int)

Swap swaps the values at two indexes in the entries slice.

type Entry

type Entry struct {
	Path  string
	Score *Score
}

Entry represents a path and a score.

func NewEntry

func NewEntry(path string) *Entry

NewEntry creates a new entry with the specified path. The score is created with NewScore.

func (*Entry) CalculateScore

func (e *Entry) CalculateScore() float64

CalculateScore calculates the score for an entry.

func (*Entry) String

func (e *Entry) String() string

func (*Entry) UpdateScore

func (e *Entry) UpdateScore(weight int64)

UpdateScore updates the score for an entry.

type FuzzyEntries

type FuzzyEntries struct {
	Entries
	Term string
}

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.

func (*FuzzyEntries) Select

func (fe *FuzzyEntries) Select(index int) (*Entry, bool)

Select selects the entry with greatest LCS score at index.

func (*FuzzyEntries) Sort

func (fe *FuzzyEntries) Sort()

Sort sorts the entries collection.

type Score

type Score struct {
	Weight int64
	Age    time.Time
}

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) Calculate

func (s *Score) Calculate() float64

Calculate the final score from the score weight and the age.

func (*Score) Relevance

func (s *Score) Relevance() float64

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.

func (*Score) String

func (s *Score) String() string

String gives a string representation to Score. Useful for debugging.

func (*Score) Update

func (s *Score) Update(weight int64)

Update the weight and age of the current score.

Jump to

Keyboard shortcuts

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