search

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 14 Imported by: 0

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

View Source
const FilterMaxCoursesCount = 3

FilterMaxCoursesCount caps how many courses one search may be limited to.

Variables

View Source
var ErrSearchUnavailable = errors.New("search is not available")

ErrSearchUnavailable means Meilisearch did not answer; locally that is the norm.

View Source
var ErrUnknownCourse = errors.New("unknown course")

ErrUnknownCourse is a course key no course matches.

Functions

func ParseCourseKeys

func ParseCourseKeys(ctx context.Context, d dao.DaoWrapper, keys []string) ([]model.Course, error)

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.

func ParseSemesterKeys

func ParseSemesterKeys(keys []string) ([]model.Semester, error)

ParseSemesterKeys reads semesters written as v1's URL parameter did: "2022S".

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 SearchCourseDTO struct {
	Name         string `json:"name"`
	Slug         string `json:"slug"`
	Year         int    `json:"year"`
	TeachingTerm string `json:"semester"`
}

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 SearchStreamDTO struct {
	ID           uint   `json:"ID"`
	Name         string `json:"name"`
	Description  string `json:"description"`
	CourseName   string `json:"courseName"`
	Year         int    `json:"year"`
	TeachingTerm string `json:"semester"`
	CourseSlug   string `json:"courseSlug"`
}

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"`
}

Jump to

Keyboard shortcuts

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