Help us shape the future of Go! Take the 2026 Go Developer Survey

fuzzy

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package fuzzy scores candidate strings against a subsequence query and ranks them, backing the file and revision pickers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Score

func Score(text, query string) (int, []int)

Score calculates fuzzy match score for a query against text Higher score is better. Returns 0 if no match.

Algorithm: - Consecutive character matches get bonus points - Case-sensitive matches get bonus points - Matches at word boundaries get bonus points - Earlier matches get higher scores.

Types

type Match

type Match struct {
	Text     string
	Score    int
	Matched  bool
	Indices  []int
	Original interface{}
}

Match is one scored candidate. Indices holds the ascending byte offsets in Text that the query matched, and Original carries whatever value the caller paired with the candidate. Matched is false on the unranked passthrough Filter returns for an empty query.

func Filter

func Filter(query string, items []string) []Match

Filter returns matches sorted by score (highest first).

func FilterWithData

func FilterWithData(query string, items []string, data []interface{}) []Match

FilterWithData is like Filter but preserves arbitrary data with each item.

Jump to

Keyboard shortcuts

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