Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Algorithm ¶ added in v0.3.0
type Algorithm interface { // AppendCands appends candidates to the engine. AppendCands([]*Candidate) // DeleteCands deletes candidates from the engine. DeleteCands() // GetQuery returns the current query. GetQuery() []rune // AddQuery adds a rune to the query. AddQuery(rune) // RmQuery removes a rune from the query. RmQuery() // DelQuery deletes (clears) the query. DelQuery() }
Algorithm is the interface for the algorithm used by the engine.
Algorithm can be non transitive. So, you can implement a algorithm that calculates with whole query every time.
type Candidate ¶
type Candidate struct { // Ptr is a arbitrary pointer. // If you want to Engine to return a pointer to some object as a search result, you can use this field. Ptr any // Text is a string to be searched. Text []rune // Matched is true if the candidate is matched. Matched bool // KeyRunes is a list of key runes. // It is intended to be used to highlight matched runes. // // Even if Matched is true, len(KeyRunes) != len(query) may be true. // It depends on the algorithm you use. // (Some algorithms may not use KeyRunes at all.) KeyRunes []KeyRune }
Candidate is a candidate for incremental search.
func NewCandidate ¶ added in v0.3.0
NewCandidate Makes a new Candidate.
func Strs2Cands ¶
Strs2Cands converts a list of strings to a list of Candidates.
Ptr of each Candidate will be set to nil for decreasing memory usage.
type Engine ¶
type Engine struct { Algorithm // contains filtered or unexported fields }
Engine is a engine for incremental search.
func New ¶
New returns a new Engine.
It uses the default algorithm which is naive incremental search.
func NewWithAlgo ¶ added in v0.4.0
NewWithAlgo returns a new Engine with a custom algorithm.
func (*Engine) AppendCands ¶ added in v0.4.0
AppendCands appends candidates to the engine.
It receives candidates as values and converts them to pointers. So, you can't modify the candidates after passing them to AppendCands.
func (*Engine) Candidates ¶ added in v0.5.0
Candidates returns all candidates.
func (*Engine) DeleteCands ¶ added in v0.6.0
func (e *Engine) DeleteCands()
DeleteCands deletes all candidates from the engine.
type KeyRune ¶ added in v0.4.0
type KeyRune struct { // Pos is the index of the first rune of the runes which are matched. Pos uint // Len is length of the rune starts with target[Pos]. Len uint }
KeyRune represents a important rune in a candidate.Text. It is intended to be used to highlight matched runes.
Use like this:
target[Pos:] target[Pos:Pos+Len]
Former is the substring from the key rune to the end of the target. Latter is one key runes with proper length.
If multibyte (non-ASCII) characters are not used, you may use only Pos.