Documentation
¶
Overview ¶
Package search provides a search abstraction layer with pluggable backends. This replaces the google.golang.org/appengine/search dependency with an interface-based approach supporting multiple backends (Meilisearch, Elasticsearch, SQL LIKE queries, or in-memory).
Index ¶
- Variables
- func Delete(ctx context.Context, indexName string, id string) error
- func Get(ctx context.Context, indexName string, id string, doc interface{}) error
- func Put(ctx context.Context, indexName string, id string, doc interface{}) (string, error)
- func SetBackend(b Backend)
- type Atom
- type Backend
- type Facet
- type FacetResult
- type FacetSearchOption
- type Index
- type Iterator
- type Range
- type SearchOptions
- type SortExpression
- type SortOptions
Constants ¶
This section is empty.
Variables ¶
var ( // Done is returned by Iterator.Next when the iteration is complete. Done = errors.New("search: no more results") // ErrNoBackend is returned when no search backend is configured. ErrNoBackend = errors.New("search: no backend configured") // ErrIndexNotFound is returned when the requested index doesn't exist. ErrIndexNotFound = errors.New("search: index not found") )
Common errors
Functions ¶
Types ¶
type Backend ¶
type Backend interface {
// Open returns an Index for the given name.
Open(name string) (Index, error)
// Close releases any resources held by the backend.
Close() error
}
Backend is the interface that search backends must implement.
type Facet ¶
type Facet struct {
// Name is the facet field name.
Name string
// Value is the facet value (Atom, Range, or string).
Value interface{}
}
Facet represents a facet value for filtering or in results.
type FacetResult ¶
type FacetResult struct {
// Name is the facet field name.
Name string
// Value is the facet value.
Value interface{}
// Count is the number of documents with this facet value.
Count int
}
FacetResult represents a facet value in search results.
type FacetSearchOption ¶
type FacetSearchOption struct {
// Name is the facet field name (empty for auto-discovery).
Name string
// ValueLimit limits the number of values returned per facet.
ValueLimit int
// DiscoveryLimit limits the number of facets discovered (for auto-discovery).
DiscoveryLimit int
}
FacetSearchOption configures facet discovery in search.
func AutoFacetDiscovery ¶
func AutoFacetDiscovery(discoveryLimit, valueLimit int) FacetSearchOption
AutoFacetDiscovery returns a FacetSearchOption for automatic facet discovery.
type Index ¶
type Index interface {
// Search performs a search query and returns an iterator.
Search(ctx context.Context, query string, opts *SearchOptions) Iterator
// Put indexes a document with the given ID.
Put(ctx context.Context, id string, doc interface{}) (string, error)
// Get retrieves a document by ID.
Get(ctx context.Context, id string, doc interface{}) error
// Delete removes a document by ID.
Delete(ctx context.Context, id string) error
}
Index represents a searchable index.
type Iterator ¶
type Iterator interface {
// Next returns the next result. Returns Done when iteration is complete.
Next(dst interface{}) (string, error)
// Count returns the total number of results (may be approximate).
Count() int
// Facets returns facet results if requested.
Facets() ([][]FacetResult, error)
}
Iterator iterates over search results.
type SearchOptions ¶
type SearchOptions struct {
// IDsOnly returns only document IDs, not full documents.
IDsOnly bool
// Limit is the maximum number of results to return.
Limit int
// Offset is the number of results to skip.
Offset int
// Sort configures result sorting.
Sort *SortOptions
// Refinements filters results by facet values.
Refinements []Facet
// Facets configures which facets to return.
Facets []FacetSearchOption
// CountAccuracy configures count accuracy.
CountAccuracy int
}
SearchOptions configures a search query.
type SortExpression ¶
type SortExpression struct {
// Expr is the field to sort by.
Expr string
// Reverse sorts in descending order if true.
Reverse bool
// Default is the default value for missing fields.
Default interface{}
}
SortExpression defines a sort field and direction.
type SortOptions ¶
type SortOptions struct {
Expressions []SortExpression
}
SortOptions configures result sorting.