query

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: EUPL-1.2 Imports: 19 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 added in v0.14.0

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 added in v0.12.0

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 added in v0.12.0

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 ContextDirection added in v0.13.0

type ContextDirection uint8

ContextDirection specifies the direction a context should be calculated.

const (
	ContextDirBoth ContextDirection = iota
	ContextDirForward
	ContextDirBackward
)

type ContextPort added in v0.13.0

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 added in v0.13.0

type ContextSpec struct {
	Direction ContextDirection
	MaxCost   int
	MaxCount  int
	Full      bool
}

ContextSpec contains all specification values for calculating a context.

func (*ContextSpec) Execute added in v0.13.0

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

func (*ContextSpec) Print added in v0.13.0

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

type Directive added in v0.13.0

type Directive interface {
	Print(*PrintEnv)
}

Directive are executed to process the list of metadata.

type IdentSpec added in v0.13.0

type IdentSpec struct{}

IdentSpec contains all specification values to calculate the ident directive.

func (*IdentSpec) Print added in v0.13.0

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

type ItemsSpec added in v0.13.0

type ItemsSpec struct{}

ItemsSpec contains all specification values to calculate items.

func (*ItemsSpec) Print added in v0.13.0

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

type MetaMatchFunc

type MetaMatchFunc func(*meta.Meta) bool

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

type PrintEnv added in v0.13.0

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 added in v0.13.0

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

GetDirectives returns the slice of query directives.

func (*Query) GetMetaValues added in v0.14.0

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

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 added in v0.10.0

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

GetSeed returns the seed value if one was set.

func (*Query) GetZids added in v0.13.0

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

GetZids returns a slide of all specified zettel identifier.

func (*Query) Human

func (q *Query) Human() 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 added in v0.12.0

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 added in v0.10.0

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 NKFD, trimmed and not empty.
	SearchEqual(word string) id.Set

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

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

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

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

type UnlinkedSpec added in v0.13.0

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

UnlinkedSpec contains all specification values to calculate unlinked references.

func (*UnlinkedSpec) GetWords added in v0.13.0

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

func (*UnlinkedSpec) Print added in v0.13.0

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

Jump to

Keyboard shortcuts

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