Documentation
¶
Overview ¶
Package search is the Meilisearch-backed search of courses, lectures and subtitles, including the filters that decide who may find what.
Index ¶
- Constants
- Variables
- func ParseCourseKeys(ctx context.Context, d dao.DaoWrapper, keys []string) ([]model.Course, error)
- func ParseSemesterKeys(keys []string) ([]model.Semester, error)
- type SearchCatalog
- type SearchCourseDTO
- type SearchHits
- type SearchScope
- type SearchStreamDTO
- type SearchSubtitlesDTO
Constants ¶
const FilterMaxCoursesCount = 3
FilterMaxCoursesCount caps how many courses one search may be limited to.
Variables ¶
ErrSearchUnavailable means Meilisearch did not answer; locally that is the norm.
var ErrUnknownCourse = errors.New("unknown course")
ErrUnknownCourse is a course key no course matches.
Functions ¶
func ParseCourseKeys ¶
ParseCourseKeys reads courses written as v1's URL parameter did: "<slug><year><term>", "brauereiwesen2022S". It answers ErrUnknownCourse for a key no course matches or that is malformed, which the caller should treat as a missing course.
Types ¶
type SearchCatalog ¶
type SearchCatalog struct {
Dao dao.DaoWrapper
Meili tools.MeiliSearchInterface
}
SearchCatalog is the search the v2 API exposes. It builds the filters and post-filters the hits (filters.go) so that who may find what is decided in one place.
func (SearchCatalog) Search ¶
func (s SearchCatalog) Search(ctx context.Context, user *model.User, query string, limit int64, scope SearchScope) (SearchHits, error)
Search runs the query for user (nil for an anonymous caller) and keeps at most limit hits of each kind.
type SearchCourseDTO ¶
type SearchHits ¶
type SearchHits struct {
Courses []SearchCourseDTO
Streams []SearchStreamDTO
Subtitles []SearchSubtitlesDTO
}
SearchHits is what a search found, already reduced to what the user may see.
type SearchScope ¶
type SearchScope struct {
Semesters []model.Semester
// A range; both or neither. Ignored when Semesters is set.
FirstSemester, LastSemester *model.Semester
// Searching inside courses looks at their lectures and subtitles instead of at
// courses, hidden ones included: naming a course is opting into it. The caller
// has checked the user may watch each.
Courses []model.Course
// Only courses, never lectures.
CoursesOnly bool
}
SearchScope narrows a search: named semesters, a range of them, or up to FilterMaxCoursesCount courses the caller may watch.
type SearchStreamDTO ¶
type SearchSubtitlesDTO ¶
type SearchSubtitlesDTO struct {
StreamID uint `json:"streamID"`
Timestamp int64 `json:"timestamp"`
TextPrev string `json:"textPrev"` // the previous subtitle line
Text string `json:"text"`
TextNext string `json:"textNext"` // the next subtitle line
StreamName string `json:"streamName"`
StreamStartTime time.Time `json:"streamStartTime"`
StreamEndTime time.Time `json:"streamEndTime"`
CourseName string `json:"courseName"`
CourseSlug string `json:"courseSlug"`
CourseYear int `json:"year"`
CourseTeachingTerm string `json:"semester"`
}