search

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 5 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 search parses the search language (docs/specs/search.md) into a Query the store turns into SQL over messages and messages_fts. Parse is forgiving: anything it does not understand becomes a text term. Match and Exclude build the FTS5 expressions for the terms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRelative

func ParseRelative(v string, now time.Time, loc *time.Location) (time.Time, bool)

ParseRelative reads Nd, Nw, Nm or Ny (N >= 1) as midnight in loc of the day N days, weeks, 30-day months or 365-day years before now's day in loc: newer_than: and older_than:, and the within and notwithin conditions (docs/design/organize.md).

func ToConditions

func ToConditions(q Query, loc *time.Location) api.Conditions

ToConditions turns a parsed search into conditions that list the same messages (docs/design/organize.md, From a search), for Save as Smart Mailbox. Dates are days in loc; newer_than: and older_than: stay relative.

Types

type Query

type Query struct {
	Terms         []Term            // full-text conditions, in input order
	Unread        *bool             // is:unread / is:read
	Flagged       *bool             // is:flagged / -is:flagged
	HasAttachment *bool             // has:attachment / -has:attachment
	After         time.Time         // inclusive lower bound (zero: none)
	Before        time.Time         // exclusive upper bound (zero: none)
	Roles         []api.MailboxRole // in:inbox, in:sent, … (any of them)
	// AfterRel and BeforeRel are newer_than: and older_than:'s values
	// ("2d") when After or Before came from one, so a saved search stays
	// relative (ToConditions).
	AfterRel, BeforeRel string
}

Query is a parsed search.

func Parse

func Parse(text string, now time.Time, loc *time.Location) Query

Parse reads the search language. It never fails: unknown or malformed operators become text terms.

func (Query) Empty

func (q Query) Empty() bool

Empty reports whether the query has no condition at all.

func (Query) Exclude

func (q Query) Exclude() string

Exclude is the FTS5 expression matching any negated term ("" when none).

func (Query) Match

func (q Query) Match() string

Match is the FTS5 expression for the positive terms ("" when none).

type Term

type Term struct {
	Column string // "" (any column), "subject", "from_text", "to_text", "attachment_names"
	Text   string // the words, as typed, quotes removed
	Phrase bool   // typed in double quotes
	Not    bool   // prefixed with "-"
}

Term is one full-text condition.

func Words

func Words(value, column string) []Term

Words splits a condition's value into terms on column, as the search field would: a value wholly in double quotes is one phrase, otherwise each whitespace-separated word with a letter or digit is a prefix term.

Jump to

Keyboard shortcuts

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