search

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPrefixQuery

func BuildPrefixQuery(userInput string) string

BuildPrefixQuery creates an FTS5 query for typeahead/prefix search. It sanitizes the input and appends a wildcard for prefix matching.

func RegisterRoutesWithGroup

func RegisterRoutesWithGroup(g *echo.Group, db *bun.DB)

RegisterRoutesWithGroup registers search routes on a pre-configured group.

func SanitizeFTSQuery

func SanitizeFTSQuery(input string) string

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 NewService(db *bun.DB) *Service

func (*Service) DeleteFromBookIndex

func (svc *Service) DeleteFromBookIndex(ctx context.Context, bookID int) error

DeleteFromBookIndex removes a book from the FTS index.

func (*Service) DeleteFromGenreIndex

func (svc *Service) DeleteFromGenreIndex(ctx context.Context, genreID int) error

DeleteFromGenreIndex removes a genre from the FTS index.

func (*Service) DeleteFromPersonIndex

func (svc *Service) DeleteFromPersonIndex(ctx context.Context, personID int) error

DeleteFromPersonIndex removes a person from the FTS index.

func (*Service) DeleteFromSeriesIndex

func (svc *Service) DeleteFromSeriesIndex(ctx context.Context, seriesID int) error

DeleteFromSeriesIndex removes a series from the FTS index.

func (*Service) DeleteFromTagIndex

func (svc *Service) DeleteFromTagIndex(ctx context.Context, tagID int) error

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) IndexBook

func (svc *Service) IndexBook(ctx context.Context, book *models.Book) error

IndexBook adds or updates a book in the FTS index.

func (*Service) IndexGenre

func (svc *Service) IndexGenre(ctx context.Context, genre *models.Genre) error

IndexGenre adds or updates a genre in the FTS index.

func (*Service) IndexPerson

func (svc *Service) IndexPerson(ctx context.Context, person *models.Person) error

IndexPerson adds or updates a person in the FTS index.

func (*Service) IndexSeries

func (svc *Service) IndexSeries(ctx context.Context, series *models.Series) error

IndexSeries adds or updates a series in the FTS index.

func (*Service) IndexTag

func (svc *Service) IndexTag(ctx context.Context, tag *models.Tag) error

IndexTag adds or updates a tag in the FTS index.

func (*Service) RebuildAllIndexes

func (svc *Service) RebuildAllIndexes(ctx context.Context) error

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.

func (*Service) SearchPeople

func (svc *Service) SearchPeople(ctx context.Context, libraryID int, query string, limit, offset int) ([]PersonSearchResult, int, error)

SearchPeople searches people.

func (*Service) SearchSeries

func (svc *Service) SearchSeries(ctx context.Context, libraryID int, query string, limit, offset int) ([]SeriesSearchResult, int, error)

SearchSeries searches series.

Jump to

Keyboard shortcuts

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