query

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: EUPL-1.2 Imports: 18 Imported by: 0

Documentation

Overview

Package query provides a query for zettel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlwaysIncluded

func AlwaysIncluded(id.Zid) bool

AlwaysIncluded is a RetrievePredicate that always returns true.

Types

type Compiled

type Compiled struct {
	PreMatch MetaMatchFunc // Precondition for Match and Retrieve
	Terms    []CompiledTerm
	// contains filtered or unexported fields
}

Compiled is a compiled query, to be used in a Box

func (*Compiled) AfterSearch

func (c *Compiled) AfterSearch(metaList []*meta.Meta) []*meta.Meta

AfterSearch applies all terms to the metadata list that was searched.

This includes sorting, offset, limit, and picking.

func (*Compiled) Result

func (c *Compiled) Result() []*meta.Meta

Result returns a result of the compiled search, that is achievable without iterating through a box.

type CompiledTerm

type CompiledTerm struct {
	Match    MetaMatchFunc     // Match on metadata
	Retrieve RetrievePredicate // Retrieve from full-text search
}

CompiledTerm is the preprocessed sequence of conjugated search terms.

type ContextPort

type ContextPort interface {
	GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error)
	SelectMeta(ctx context.Context, metaSeq []*meta.Meta, q *Query) ([]*meta.Meta, error)
}

ContextPort is the collection of box methods needed by this directive.

type ContextSpec

type ContextSpec struct {
	// contains filtered or unexported fields
}

ContextSpec contains all specification values for calculating a context.

func (*ContextSpec) Execute

func (spec *ContextSpec) Execute(ctx context.Context, startSeq []*meta.Meta, port ContextPort) []*meta.Meta

Execute the specification.

func (*ContextSpec) Print

func (spec *ContextSpec) Print(pe *PrintEnv)

Print the spec on the given print environment.

type Directive

type Directive interface {
	Print(*PrintEnv)
}

Directive are executed to process the list of metadata.

type IdentSpec

type IdentSpec struct{}

IdentSpec contains all specification values to calculate the ident directive.

func (*IdentSpec) Print

func (spec *IdentSpec) Print(pe *PrintEnv)

Print the spec on the given print environment.

type ItemsSpec

type ItemsSpec struct{}

ItemsSpec contains all specification values to calculate items.

func (*ItemsSpec) Print

func (spec *ItemsSpec) Print(pe *PrintEnv)

Print the spec on the given print environment.

type MetaMatchFunc

type MetaMatchFunc func(*meta.Meta) bool

MetaMatchFunc is a function determine whethe some metadata should be selected or not.

type PrintEnv

type PrintEnv struct {
	// contains filtered or unexported fields
}

PrintEnv is an environment where queries are printed.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query specifies a mechanism for querying zettel.

func Parse

func Parse(spec string) (q *Query)

Parse the query specification and return a Query object.

func (*Query) Actions

func (q *Query) Actions() []string

Actions returns the slice of action specifications

func (*Query) Clone

func (q *Query) Clone() *Query

Clone the query value.

func (*Query) EnrichNeeded

func (q *Query) EnrichNeeded() bool

EnrichNeeded returns true, if the query references a metadata key that is calculated via metadata enrichments.

func (*Query) GetDirectives

func (q *Query) GetDirectives() []Directive

GetDirectives returns the slice of query directives.

func (*Query) GetMetaValues

func (q *Query) GetMetaValues(key string, withMissing bool) (vals []meta.Value)

GetMetaValues returns the slice of all values specified for a given metadata key. If `withMissing` is true, all values are returned. Otherwise only those, where the comparison operator will positively search for a value.

func (*Query) GetSeed

func (q *Query) GetSeed() (int, bool)

GetSeed returns the seed value if one was set.

func (*Query) GetZids

func (q *Query) GetZids() []id.Zid

GetZids returns a slide of all specified zettel identifier.

func (*Query) Human

func (q *Query) Human() string

Human returns the query as a human readable string.

func (*Query) Limit

func (q *Query) Limit(metaList []*meta.Meta) []*meta.Meta

Limit returns only s.GetLimit() elements of the given list.

func (*Query) Parse

func (q *Query) Parse(spec string) *Query

Parse the query string and update the Query object.

func (*Query) Print

func (q *Query) Print(w io.Writer)

Print the query in a parseable form.

func (*Query) PrintHuman

func (q *Query) PrintHuman(w io.Writer)

PrintHuman the query to a writer in a human readable form.

func (*Query) RemoveActions

func (q *Query) RemoveActions()

RemoveActions will remove the action part of a query.

func (*Query) RetrieveAndCompile

func (q *Query) RetrieveAndCompile(_ context.Context, searcher Searcher, metaSeq []*meta.Meta) Compiled

RetrieveAndCompile queries the search index and returns a predicate for its results and returns a matching predicate.

func (*Query) SetDeterministic

func (q *Query) SetDeterministic() *Query

SetDeterministic signals that the result should be the same if the seed is the same.

func (*Query) SetPreMatch

func (q *Query) SetPreMatch(preMatch MetaMatchFunc) *Query

SetPreMatch sets the pre-selection predicate.

func (*Query) SetSeed

func (q *Query) SetSeed(seed int) *Query

SetSeed sets a seed value.

func (*Query) String

func (q *Query) String() string

type RetrievePredicate

type RetrievePredicate func(id.Zid) bool

RetrievePredicate returns true, if the given Zid is contained in the (full-text) search.

type Searcher

type Searcher interface {
	// Select all zettel that contains the given exact word.
	// The word must be normalized through Unicode NFKD, trimmed and not empty.
	SearchEqual(word string) *idset.Set

	// Select all zettel that have a word with the given prefix.
	// The prefix must be normalized through Unicode NFKD, trimmed and not empty.
	SearchPrefix(prefix string) *idset.Set

	// Select all zettel that have a word with the given suffix.
	// The suffix must be normalized through Unicode NFKD, trimmed and not empty.
	SearchSuffix(suffix string) *idset.Set

	// Select all zettel that contains the given string.
	// The string must be normalized through Unicode NFKD, trimmed and not empty.
	SearchContains(s string) *idset.Set
}

Searcher is used to select zettel identifier based on search criteria.

type ThreadPort added in v0.22.0

type ThreadPort interface {
	GetMeta(ctx context.Context, zid id.Zid) (*meta.Meta, error)
}

ThreadPort is the collection of box methods needed by this directive.

type ThreadSpec added in v0.22.0

type ThreadSpec struct {
	// contains filtered or unexported fields
}

ThreadSpec contains all information for a thread directive.

func (*ThreadSpec) Execute added in v0.22.0

func (spec *ThreadSpec) Execute(ctx context.Context, startSeq []*meta.Meta, port ThreadPort) []*meta.Meta

Execute the specification.

func (*ThreadSpec) Print added in v0.22.0

func (spec *ThreadSpec) Print(pe *PrintEnv)

Print the spec on the given print environment.

type UnlinkedSpec

type UnlinkedSpec struct {
	// contains filtered or unexported fields
}

UnlinkedSpec contains all specification values to calculate unlinked references.

func (*UnlinkedSpec) GetWords

func (spec *UnlinkedSpec) GetWords(metaSeq []*meta.Meta) []string

GetWords returns all title words of a given query result.

func (*UnlinkedSpec) Print

func (spec *UnlinkedSpec) Print(pe *PrintEnv)

Print the spec on the given print environment.

Jump to

Keyboard shortcuts

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