search

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package search provides full-text grep-style search over vault files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRoles added in v1.7.0

func BuildRoles(todoSym, doneSym string, states []string) map[string]string

BuildRoles returns a role-name -> symbol map for the standard task roles, using the same checkbox configuration as the viewer.

func HasOperators added in v1.7.0

func HasOperators(query string) bool

HasOperators reports whether query contains any structured operator token. Plain-text queries return false and can be handled by the normal FTS path.

func LineMatchesAll added in v1.7.0

func LineMatchesAll(tokens []Token, line string, roles map[string]string) bool

LineMatchesAll returns true when line satisfies all tokens.

func LineMatchesGroups added in v1.7.0

func LineMatchesGroups(line string, groups [][]Token, hasXor bool, roles map[string]string) bool

func ScopeMatchLines added in v1.7.0

func ScopeMatchLines(tok Token, lines []string, anchorOnly bool) []int

ScopeMatchLines returns line indices satisfying the scope token over lines.

func SplitQueryGroups added in v1.7.0

func SplitQueryGroups(toks []Token) (groups [][]Token, hasXor bool)

SplitQueryGroups splits tokens on OR/XOR separators into AND-groups. hasXor is true only when XOR appears and OR does not.

func StripVaultPrefix

func StripVaultPrefix(path string, cfg *config.Config) string

StripVaultPrefix removes the vault path prefix for display.

Types

type FileMatch

type FileMatch struct {
	File         string
	FirstLine    int
	FirstContent string
}

FileMatch represents a file that contains matches with its first match for context.

func Search(pattern string, dirs []string) ([]FileMatch, error)

Search searches directories recursively for a pattern, returning matching files with context (first matching line).

func SearchWithQuery added in v1.7.0

func SearchWithQuery(query string, dirs []string, todoSym, doneSym string, states []string) ([]FileMatch, error)

SearchWithQuery searches dirs for files that contain at least one line satisfying all tokens parsed from query.

type Result

type Result struct {
	File    string
	Line    int
	Content string
}

Result represents a single search match.

type SubTerm added in v1.7.0

type SubTerm struct {
	Value string
	Neg   bool
}

SubTerm is a single term within a scope operator argument. Neg=true means the term must NOT appear.

type Token added in v1.7.0

type Token struct {
	Kind     TokenKind
	Value    string    // text for TokenText/TokenNeg, role name for TokenTaskRole, tag for TokenTag
	SubQuery string    // optional trailing text filter for task operators
	SubTerms []SubTerm // non-nil for TokenSection/Block/Subtask
}

Token is one parsed unit of a search query.

func ParseQuery added in v1.7.0

func ParseQuery(query string) []Token

ParseQuery parses a full search query into tokens. Returns nil for an empty query.

type TokenKind added in v1.7.0

type TokenKind int

TokenKind classifies a single parsed search token.

const (
	TokenText     TokenKind = iota // plain word or quoted phrase (must match)
	TokenNeg                       // -term: line must NOT contain value
	TokenTask                      // task: - any checkbox line
	TokenTaskRole                  // task-<role>: - checkbox with specific role symbol
	TokenTag                       // tag:<name> - line contains #<name>
	TokenSection                   // section:(A B) - sub-terms must co-occur in same heading section
	TokenBlock                     // block:(A B)   - sub-terms must co-occur in same paragraph
	TokenSubtask                   // subtask:(A B) - line is a subtask of a task matching sub-terms
	TokenOr                        // separator: OR keyword between AND-groups
	TokenXor                       // separator: XOR keyword between AND-groups
)

Jump to

Keyboard shortcuts

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