filter

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package filter narrows the list of gists: words found in order in a gist's description or file names, and key:value terms that look in one thing only: file:, desc:, vis: and lang:.

Index

Constants

View Source
const (
	FileKey = "file:"
	DescKey = "desc:"
	VisKey  = "vis:"
	LangKey = "lang:"
)

The keys, with their colon.

Variables

Keys are the keys.

Functions

func Fuzzy

func Fuzzy(pattern, s string) (score int, hits []int, ok bool)

Fuzzy reports whether the runes of pattern appear in s in order, ignoring case, and scores the match: consecutive runes and runes at the start of a word (after / - _ . or a space) count more, gaps count against it. hits are the rune indexes in s that matched.

It takes the first place the whole pattern fits, then the latest start that still fits before that end, so "app" in "a/b/app" matches the word rather than the stray a, moved back to a word start if one has the first rune ("bdot" in "babarot/dotfiles" starts at the first b).

func KeyRest

func KeyRest(query string) string

KeyRest is what is left to type of the key the last word of query starts, with its colon, once that word has two letters and fits one key only. A word of a description often starts like a key, so one letter is too little.

func LastWord

func LastWord(query string) string

LastWord is the word query ends with, "" after a space.

func ValueTerm

func ValueTerm(word string) (key, value string, ok bool)

ValueTerm says word is a key whose values can be listed, with what it has of a value so far. A description has none: it is whatever was written.

Types

type Hits

type Hits struct {
	Description []int
	// File is of the first file name.
	File []int
}

Hits are the runes that matched, to show. Each is sorted.

func Match

func Match(q Query, it Item) (Hits, bool)

Match says whether it matches and what did.

type Item

type Item struct {
	Description string
	Files       []string
	Languages   []string
	Public      bool
}

Item is what is looked in.

type Query

type Query struct {
	Words []string
	// File and Desc are parts of a file name or the description, Vis is secret
	// or public, Lang part of a file's language. Several of one key match any
	// of them.
	File, Desc, Vis, Lang []string
}

Query is the parsed filter, lower-cased.

func Parse

func Parse(s string) Query

Parse reads a filter. A word with an unknown key, such as a URL, is a plain word; a known key with nothing after it is nothing.

func (Query) Empty

func (q Query) Empty() bool

Empty says the query narrows nothing.

Jump to

Keyboard shortcuts

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