Documentation
¶
Overview ¶
Package filter is the single source of truth for the todo list's filter query language. It parses free-text qualifiers (label:, date:, has:, and bare search terms) into a Query and evaluates it against a board's todos, preserving tree context by keeping every ancestor of a match visible.
The package has no dependency on the models or db packages: callers map their persisted todos into the small Item projection. The reference date ("today") is supplied by the caller so date presets (week, today, tomorrow) resolve deterministically and are unit-testable without touching the system clock.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
ID int64
ParentID *int64
Position int // sibling index (used for stable ordering when sorting)
Title string
Description string
Completed bool
Labels []string
Priority string // priority name, "" = none
PriorityRank int // user-defined priority order (-1 = no rank / ad-hoc)
DueDate string // "YYYY-MM-DD" or "" (none)
HasRecurrence bool
}
Item is the projection of a todo needed to evaluate a filter.
func Apply ¶
Apply evaluates q against a board's todos and returns the subset that should be visible: every matching item plus the ancestors that keep the tree connected, in the original input order. An empty query returns all items unchanged. today is the reference ISO date.
func Sort ¶
Sort reorders items so each sibling group is sorted by the query's sort keys in declared order, preserving input order for equal keys (normally the database manual order by position then id). It also reassigns each item's Position to its new 0-based sibling index, so downstream consumers (e.g. the rendered tree) reflect the new order without bespoke handling. When q has no sort keys the slice is returned unchanged.
Sort operates per sibling group (items sharing a parent) so the tree's hierarchical structure is preserved — sorting never moves a todo out of its parent.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is a parsed filter expression. All criteria are ANDed; a todo matches only when it satisfies every active criterion. Its fields are unexported so the grammar stays in one place; use Parse and Query.Match.
func Parse ¶
Parse tokenises the query text into a Query. label and date accept a leading "!" for negation; has accepts one of complete/label/recur/date. Unrecognized date or has values return an error so the caller can surface it rather than silently dropping the token.