query

package
v0.6.0-preview1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BooleanQuery

type BooleanQuery struct {
	Must    []Filter      // AND conditions
	Should  []Filter      // OR conditions
	MustNot []Filter      // NOT conditions
	Nested  *BooleanQuery // Nested boolean query (for parentheses)
}

BooleanQuery represents a boolean combination of filters

type Builder

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

Builder handles converting queries into SQL

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new query builder with default assets table config

func NewSearchIndexBuilder added in v0.6.0

func NewSearchIndexBuilder() *Builder

NewSearchIndexBuilder creates a builder optimized for search_index table

func (*Builder) BuildConditions

func (b *Builder) BuildConditions(bq *BooleanQuery) ([]string, []interface{}, error)

func (*Builder) BuildSQL

func (b *Builder) BuildSQL(q *Query, baseQuery string) (string, []interface{}, error)

BuildSQL converts a Query into a SQL query with parameters

func (*Builder) BuildSearchConditions added in v0.6.0

func (b *Builder) BuildSearchConditions(q *Query, startParam int) ([]string, []interface{}, int, error)

BuildSearchConditions builds WHERE clause conditions from a Query struct. Returns conditions, params, next param index, and any error. This is designed for integration with custom query builders like the search store.

type FieldType added in v0.4.0

type FieldType string

FieldType represents the type of field being queried

const (
	FieldMetadata  FieldType = "metadata"
	FieldAssetType FieldType = "type"
	FieldProvider  FieldType = "provider"
	FieldKind      FieldType = "kind"
	FieldName      FieldType = "name"
)

type Filter

type Filter struct {
	Field     []string    // Field to filter on (e.g., "metadata.owner")
	FieldType FieldType   // Type of field (metadata, type, provider, kind)
	Operator  Operator    // Operator (e.g., =, :, contains)
	Value     interface{} // Value to compare against
	Range     *RangeValue // Range values for range queries
	OrigQuery string
}

Filter represents a single filter condition

type Operator

type Operator string

Operator represents the type of filter operation

const (
	OpEquals       Operator = "="
	OpContains     Operator = "contains"
	OpNotEquals    Operator = "!="
	OpGreater      Operator = ">"
	OpLess         Operator = "<"
	OpGreaterEqual Operator = ">="
	OpLessEqual    Operator = "<="
	OpIn           Operator = "in"
	OpNotIn        Operator = "not in"
	OpRange        Operator = "range"
	OpWildcard     Operator = "wildcard"
	OpFreeText     Operator = "freetext"
)

type Parser

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

Parser handles parsing of search queries into structured formats

func NewParser

func NewParser() *Parser

NewParser creates a new query parser

func (*Parser) Parse

func (p *Parser) Parse(queryStr string) (*Query, error)

Parse parses a search string into a structured query

type Query

type Query struct {
	FreeText string        // General text search
	Filters  []Filter      // Specific field filters
	Bool     *BooleanQuery // Boolean combinations of filters
}

Query represents a parsed search query with specific conditions

func (*Query) CanUseCompositeIndex added in v0.6.0

func (q *Query) CanUseCompositeIndex() bool

CanUseCompositeIndex checks if the query can efficiently use a composite index. Returns true if it's a simple single-field exact match on type or provider.

func (*Query) GetFreeText added in v0.6.0

func (q *Query) GetFreeText() string

GetFreeText returns the free text portion of the query

func (*Query) HasStructuredFilters added in v0.6.0

func (q *Query) HasStructuredFilters() bool

HasStructuredFilters returns true if the query has any structured filters

type RangeValue

type RangeValue struct {
	From      interface{}
	To        interface{}
	Inclusive bool
}

RangeValue represents a range query with optional bounds

type TableConfig added in v0.6.0

type TableConfig struct {
	TypeColumn     string // "type" for assets, "asset_type" for search_index
	ProviderColumn string // "providers" for both
	NameColumn     string // "name" for both
	MetadataColumn string // "metadata" for both
}

TableConfig specifies column names for different tables

func DefaultAssetsConfig added in v0.6.0

func DefaultAssetsConfig() TableConfig

DefaultAssetsConfig returns column config for the assets table

func SearchIndexConfig added in v0.6.0

func SearchIndexConfig() TableConfig

SearchIndexConfig returns column config for the search_index table

type Tokeniser

type Tokeniser struct{}

Tokeniser handles breaking down search queries into tokens

func NewTokeniser

func NewTokeniser() *Tokeniser

NewTokeniser creates a new tokenizer

func (*Tokeniser) Tokenise

func (t *Tokeniser) Tokenise(query string) ([]string, error)

Tokenise splits a query string into tokens while preserving quoted strings and operators

Jump to

Keyboard shortcuts

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