search

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APPVAR_SEARCH_BACKEND = "search.backend" // string
)

Variables

This section is empty.

Functions

func GetDefaultSearchBackend

func GetDefaultSearchBackend() (string, bool)

func IndexModels

func IndexModels[T SearchableModel](ctx context.Context, models []T) (int64, error)

func RegisterSearchBackend

func RegisterSearchBackend(name string, backend SearchBackend, setDefault ...bool)

func RemoveModelsFromIndex

func RemoveModelsFromIndex[T SearchableModel](ctx context.Context, models []T) (int64, error)
func Search[MODEL SearchableModel, SEARCHABLE any](model MODEL, query string, searchable SEARCHABLE) (SEARCHABLE, error)

Types

type BackendDefiner

type BackendDefiner interface {
	SearchBackend() SearchBackend
}

type BuiltSearchField

type BuiltSearchField struct {
	ModelField  attrs.FieldDefinition
	ModelMeta   attrs.ModelMeta
	SearchField SearchField
}

func BuildSearchFields

func BuildSearchFields[T SearchableModel](model T) ([]BuiltSearchField, error)

type SearchBackend

type SearchBackend interface {
	AddToSearchIndex(ctx context.Context, models []any) (int64, error)
	RemoveFromSearchIndex(ctx context.Context, models []any) (int64, error)
	Search(fields []BuiltSearchField, query string, searchable any) (any, error)
}

func GetSearchBackend

func GetSearchBackend(name string) (SearchBackend, bool)

func GetSearchBackendForModel

func GetSearchBackendForModel[T SearchableModel](model T) (SearchBackend, error)

type SearchField

type SearchField interface {
	Weight() int8   // higher is more important
	Field() string  // <fieldname> or <path.to.related.fieldname>
	Lookup() string // icontains, istartswith, exact, etc. (see expr.LookupFilter)
}

func NewSearchField

func NewSearchField(weight int8, field string, lookup string) SearchField

type Searchable

type Searchable interface {
	BuildSearchQuery(fields []BuiltSearchField, query string) (Searchable, error)
}

type SearchableModel

type SearchableModel interface {
	attrs.Definer
	SearchableFields() []SearchField
}

Directories

Path Synopsis
backends

Jump to

Keyboard shortcuts

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