filter

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 8 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:, lang:, owner:, size:, updated: and comments:.

Index

Constants

View Source
const (
	FileKey     = "file:"
	DescKey     = "desc:"
	VisKey      = "vis:"
	LangKey     = "lang:"
	OwnerKey    = "owner:"
	SizeKey     = "size:"
	UpdatedKey  = "updated:"
	CommentsKey = "comments:"
)

The keys, with their colon.

Variables

Keys are the keys.

Functions

func BoundHint added in v2.1.0

func BoundHint(word string) string

BoundHint says how to go on with word, a term with a bound being typed, or why it cannot be read; "" for any other word and one with nothing to add. What it shows is an example, not a value to fill in: a bound has none to offer.

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 Bound added in v2.1.0

type Bound struct {
	// Op is >, >=, <, <= or, for a number alone, =.
	Op    string
	Value float64
}

Bound is a bound on a number, such as >200kb.

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
	Owner       string
	// Size is the size of the files together, and Age how long ago it changed.
	Size     int64
	Age      time.Duration
	Comments int
}

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, Owner part of the owner's
	// login. Several of one key match any of them.
	File, Desc, Vis, Lang, Owner []string
	// Size are bounds on the size of a gist's files together and Updated on how
	// long ago it changed, in nanoseconds, and Comments on how many comments it
	// has. All of them must hold, so that two make a range.
	Size, Updated, Comments []Bound
}

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. A bound that cannot be read is a plain word too, which leaves no rows rather than all of them.

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