60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package catalog
|
|
|
|
import "context"
|
|
|
|
// Query is a value object describing a search request in domain terms.
|
|
// The domain does not know Meilisearch filter syntax; the adapter translates it.
|
|
type Query struct {
|
|
Text string
|
|
Genre string // optional facet filter
|
|
MinYear int // 0 = unbounded
|
|
MaxYear int // 0 = unbounded
|
|
MinRating float64 // 0 = unbounded
|
|
Limit int
|
|
Offset int
|
|
}
|
|
|
|
// Normalize applies defaults. Kept in the domain so every caller gets the same
|
|
// paging rules.
|
|
func (q Query) Normalize() Query {
|
|
if q.Limit <= 0 || q.Limit > 100 {
|
|
q.Limit = 20
|
|
}
|
|
if q.Offset < 0 {
|
|
q.Offset = 0
|
|
}
|
|
return q
|
|
}
|
|
|
|
// Hit is a movie plus the search metadata produced by the engine.
|
|
type Hit struct {
|
|
Movie *Movie
|
|
Formatted string // highlighted title, may be empty
|
|
}
|
|
|
|
// Facet is one facet value with its document count.
|
|
type Facet struct {
|
|
Value string
|
|
Count int
|
|
}
|
|
|
|
// Results is the outcome of a search: hits, total estimate and facets.
|
|
type Results struct {
|
|
Hits []Hit
|
|
EstimatedTotal int64
|
|
ProcessingMS int64
|
|
Genres []Facet
|
|
}
|
|
|
|
// MovieIndex is the driven port (hexagonal "right side"). The infrastructure
|
|
// layer provides a Meilisearch implementation; tests provide a fake.
|
|
type MovieIndex interface {
|
|
// EnsureSchema makes the index searchable/filterable/sortable as this
|
|
// bounded context requires. Idempotent.
|
|
EnsureSchema(ctx context.Context) error
|
|
Index(ctx context.Context, movies []*Movie) error
|
|
Get(ctx context.Context, id MovieID) (*Movie, error)
|
|
Delete(ctx context.Context, id MovieID) error
|
|
Search(ctx context.Context, q Query) (Results, error)
|
|
}
|