searchstring

package
v0.0.0-...-60192f8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package searchstring provides a search string parser.

Index

Constants

View Source
const (
	// EOF is the end of file token.
	EOF kind = iota
	// SPACE is a space token.
	SPACE
	// FIELD is a field token.
	FIELD
	// NEG is a negation token.
	NEG
	// WILDCARD is a wildcard token.
	WILDCARD
	// STR is a string token.
	STR
	// STRQ is a quoted string.
	STRQ
)

Variables

This section is empty.

Functions

func BuildSQL

func BuildSQL(ds *goqu.SelectDataset, q SearchQuery, conf *BuilderConfig) *goqu.SelectDataset

BuildSQL returns a new dataset with the search query.

Types

type BuilderConfig

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

BuilderConfig contains the configuration for the SQL builder.

func NewBuilderConfig

func NewBuilderConfig(left, right exp.IdentifierExpression, fields [][2]string) *BuilderConfig

NewBuilderConfig returns a new BuilderConfig.

type SearchQuery

type SearchQuery struct {
	Terms []SearchTerm
}

SearchQuery is a search query that can be transformed into a database query.

func ParseField

func ParseField(s, name string) (SearchQuery, error)

ParseField returns a new SearchQuery, ignoring any field definition in the tokens, but taking into acount exclusion or wildcards. "-test*" becomes a search term with wildcard and exclusion for the given label.

func ParseQuery

func ParseQuery(s string) (SearchQuery, error)

ParseQuery returns a new SearchQuery after parsing the input string.

func (SearchQuery) Dedup

func (q SearchQuery) Dedup() SearchQuery

Dedup returns a new SearchQuery without duplicate entries.

func (SearchQuery) ExtractField

func (q SearchQuery) ExtractField(name string) SearchQuery

ExtractField returns a SearchQuery with only the terms for a specific field.

func (SearchQuery) PopField

func (q SearchQuery) PopField(name string) (sq, nsq SearchQuery)

PopField returns a SearchQuery for the given field and the SearchQuery without the removed search terms. The initial SearchQuery is unchanged.

func (SearchQuery) RemoveField

func (q SearchQuery) RemoveField() SearchQuery

RemoveField returns a SearchQuery without the terms for a specific field.

func (SearchQuery) String

func (q SearchQuery) String() string

Strings returns the query as a string.

func (SearchQuery) Unfield

func (q SearchQuery) Unfield(names ...string) SearchQuery

Unfield transforms every field search term that is not in "names" into a normal string.

type SearchTerm

type SearchTerm struct {
	Field    string
	Value    string
	Exact    bool
	Exclude  bool
	Wildcard bool
}

SearchTerm is a search term part.

func (SearchTerm) String

func (st SearchTerm) String() string

String returns a term's string.

Jump to

Keyboard shortcuts

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