Documentation
¶
Index ¶
- func BuildPrefixQuery(userInput string) string
- func RegisterRoutesWithGroup(g *echo.Group, db *bun.DB)
- func SanitizeFTSQuery(input string) string
- type BookSearchResult
- type BooksQuery
- type GlobalSearchQuery
- type GlobalSearchResponse
- type PeopleQuery
- type PersonSearchResult
- type SeriesQuery
- type SeriesSearchResult
- type Service
- func (svc *Service) DeleteFromBookIndex(ctx context.Context, bookID int) error
- func (svc *Service) DeleteFromGenreIndex(ctx context.Context, genreID int) error
- func (svc *Service) DeleteFromPersonIndex(ctx context.Context, personID int) error
- func (svc *Service) DeleteFromSeriesIndex(ctx context.Context, seriesID int) error
- func (svc *Service) DeleteFromTagIndex(ctx context.Context, tagID int) error
- func (svc *Service) GlobalSearch(ctx context.Context, libraryID int, query string) (*GlobalSearchResponse, error)
- func (svc *Service) IndexBook(ctx context.Context, book *models.Book) error
- func (svc *Service) IndexGenre(ctx context.Context, genre *models.Genre) error
- func (svc *Service) IndexPerson(ctx context.Context, person *models.Person) error
- func (svc *Service) IndexSeries(ctx context.Context, series *models.Series) error
- func (svc *Service) IndexTag(ctx context.Context, tag *models.Tag) error
- func (svc *Service) RebuildAllIndexes(ctx context.Context) error
- func (svc *Service) SearchBooks(ctx context.Context, libraryID int, query string, fileTypes []string, ...) ([]BookSearchResult, int, error)
- func (svc *Service) SearchPeople(ctx context.Context, libraryID int, query string, limit, offset int) ([]PersonSearchResult, int, error)
- func (svc *Service) SearchSeries(ctx context.Context, libraryID int, query string, limit, offset int) ([]SeriesSearchResult, int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildPrefixQuery ¶
BuildPrefixQuery creates an FTS5 query for typeahead/prefix search. It sanitizes the input and appends a wildcard for prefix matching.
func RegisterRoutesWithGroup ¶
RegisterRoutesWithGroup registers search routes on a pre-configured group.
func SanitizeFTSQuery ¶
SanitizeFTSQuery escapes FTS5 special characters and wraps in quotes for literal matching. FTS5 has its own query language with operators (AND, OR, NOT, *, NEAR(), :, ", etc.). Even with parameterized queries, the FTS5 engine interprets these. This function ensures user input is treated as a literal phrase.
Types ¶
type BookSearchResult ¶
type BookSearchResult struct {
ID int `json:"id"`
Title string `json:"title"`
Subtitle *string `json:"subtitle"`
Authors string `json:"authors"` // Comma-separated author names
FileTypes []string `json:"file_types"` // Unique file types for this book (e.g., ["epub", "m4b"])
LibraryID int `json:"library_id"`
}
BookSearchResult represents a book in search results.
type BooksQuery ¶
type BooksQuery struct {
Query string `query:"search" json:"search,omitempty" validate:"omitempty,max=100"`
LibraryID *int `query:"library_id" json:"library_id,omitempty" validate:"omitempty,min=1" tstype:"number"`
FileTypes []string `query:"file_types" json:"file_types,omitempty"` // Filter by file types (e.g., ["epub", "m4b"])
Limit int `query:"limit" json:"limit,omitempty" default:"24" validate:"min=1,max=50"`
Offset int `query:"offset" json:"offset,omitempty" validate:"min=0"`
}
BooksQuery represents the query parameters for book search.
type GlobalSearchQuery ¶
type GlobalSearchQuery struct {
Query string `query:"q" json:"q" validate:"required,min=1,max=100"`
LibraryID int `query:"library_id" json:"library_id" validate:"required,min=1"`
}
GlobalSearchQuery represents the query parameters for global search.
type GlobalSearchResponse ¶
type GlobalSearchResponse struct {
Books []BookSearchResult `json:"books"`
Series []SeriesSearchResult `json:"series"`
People []PersonSearchResult `json:"people"`
}
GlobalSearchResponse represents the response from global search. Returns up to 5 results per resource type for popover display.
type PeopleQuery ¶
type PeopleQuery struct {
Query string `query:"search" json:"search,omitempty" validate:"omitempty,max=100"`
LibraryID *int `query:"library_id" json:"library_id,omitempty" validate:"omitempty,min=1" tstype:"number"`
Limit int `query:"limit" json:"limit,omitempty" default:"24" validate:"min=1,max=50"`
Offset int `query:"offset" json:"offset,omitempty" validate:"min=0"`
}
PeopleQuery represents the query parameters for people search.
type PersonSearchResult ¶
type PersonSearchResult struct {
ID int `json:"id"`
Name string `json:"name"`
SortName string `json:"sort_name"`
LibraryID int `json:"library_id"`
}
PersonSearchResult represents a person in search results.
type SeriesQuery ¶
type SeriesQuery struct {
Query string `query:"search" json:"search,omitempty" validate:"omitempty,max=100"`
LibraryID *int `query:"library_id" json:"library_id,omitempty" validate:"omitempty,min=1" tstype:"number"`
Limit int `query:"limit" json:"limit,omitempty" default:"24" validate:"min=1,max=50"`
Offset int `query:"offset" json:"offset,omitempty" validate:"min=0"`
}
SeriesQuery represents the query parameters for series search.
type SeriesSearchResult ¶
type SeriesSearchResult struct {
ID int `json:"id"`
Name string `json:"name"`
BookCount int `json:"book_count"`
LibraryID int `json:"library_id"`
}
SeriesSearchResult represents a series in search results.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) DeleteFromBookIndex ¶
DeleteFromBookIndex removes a book from the FTS index.
func (*Service) DeleteFromGenreIndex ¶
DeleteFromGenreIndex removes a genre from the FTS index.
func (*Service) DeleteFromPersonIndex ¶
DeleteFromPersonIndex removes a person from the FTS index.
func (*Service) DeleteFromSeriesIndex ¶
DeleteFromSeriesIndex removes a series from the FTS index.
func (*Service) DeleteFromTagIndex ¶
DeleteFromTagIndex removes a tag from the FTS index.
func (*Service) GlobalSearch ¶
func (svc *Service) GlobalSearch(ctx context.Context, libraryID int, query string) (*GlobalSearchResponse, error)
GlobalSearch searches across books, series, and people in a library. Returns up to 5 results per resource type for popover display.
func (*Service) IndexGenre ¶
IndexGenre adds or updates a genre in the FTS index.
func (*Service) IndexPerson ¶
IndexPerson adds or updates a person in the FTS index.
func (*Service) IndexSeries ¶
IndexSeries adds or updates a series in the FTS index.
func (*Service) RebuildAllIndexes ¶
RebuildAllIndexes rebuilds all FTS indexes from scratch. This should be called after a scan job completes.
func (*Service) SearchBooks ¶
func (svc *Service) SearchBooks(ctx context.Context, libraryID int, query string, fileTypes []string, limit, offset int) ([]BookSearchResult, int, error)
SearchBooks searches books with optional file type filter.