Documentation
¶
Index ¶
- Constants
- func GetDefaultSearchBackend() (string, bool)
- func IndexModels[T SearchableModel](ctx context.Context, models []T) (int64, error)
- func RegisterSearchBackend(name string, backend SearchBackend, setDefault ...bool)
- 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)
- type BackendDefiner
- type BuiltSearchField
- type SearchBackend
- type SearchField
- type Searchable
- type SearchableModel
Constants ¶
View Source
const (
APPVAR_SEARCH_BACKEND = "search.backend" // string
)
Variables ¶
This section is empty.
Functions ¶
func GetDefaultSearchBackend ¶
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)
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
}
Click to show internal directories.
Click to hide internal directories.