library

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package library answers one question: does the user already own this book?

It is used in two places that must agree — the wishlist cleaner (which deletes wishlist rows once the book lands) and search/download ownership detection (which flags and blocks duplicate grabs). Both compare a loose, human-entered title against the titles the importer wrote into library_items, so the normalization lives here rather than being reinvented per caller.

Matching is deliberately conservative. A false positive tells a user they own a book they do not, and hides the download behind an extra click; that is a worse failure than missing a match, so every rule here only ever removes noise that cannot change which book is meant.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorMatches

func AuthorMatches(wantNormalized, raw string) bool

AuthorMatches reports whether a normalized author agrees with a raw author field that may hold several names ("Neil Gaiman & Terry Pratchett"). An empty wanted author agrees with anything; a known wanted author never agrees with a blank field.

func DefaultMediaType

func DefaultMediaType(mediaType string) string

DefaultMediaType normalizes a possibly-empty media type. Search results from the ebook tab often carry no media type at all.

func KnownAuthor

func KnownAuthor(author string) string

KnownAuthor returns the normalized author name, or "" when the field carries no usable name.

func NormalizePerson

func NormalizePerson(s string) string

NormalizePerson folds an author name to its comparable form.

func NormalizeTitle

func NormalizeTitle(s string) string

NormalizeTitle folds a title to its comparable form: lowercase, punctuation collapsed to single spaces, edition noise removed.

Collapsing punctuation is what makes "4:50 from Paddington" and "4.50 From Paddington" the same book — both become "4 50 from paddington".

func NormalizeWords

func NormalizeWords(s string) string

NormalizeWords lowercases, drops punctuation and symbols, and collapses whitespace runs to a single space.

func SplitAuthorList

func SplitAuthorList(author string) []string

SplitAuthorList splits a multi-author field on the separators sources actually use.

Types

type Candidate

type Candidate struct {
	ID        int64
	Title     string
	Author    string
	MediaType string
}

Candidate is the slim projection of a library row needed to answer ownership. Loading whole models.LibraryItem values (file paths, metadata blobs, hashes) for every one of a 3,000+ book library on each search would be pure waste.

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index is an ownership lookup built once from the library table and then queried per search result. Lookups are map hits, so annotating a full page of results costs nothing measurable.

The zero value is a usable empty index that matches nothing, so callers with no database do not need a nil check.

func NewIndex

func NewIndex(candidates []Candidate) *Index

NewIndex builds an ownership index from library rows.

func (*Index) Len

func (i *Index) Len() int

Len reports how many distinct title/media-type keys the index holds.

func (*Index) Lookup

func (i *Index) Lookup(title, author, mediaType string) (Match, bool)

Lookup reports whether a search result names a book already in the library.

A hit requires the normalized titles to be equal — after stripping the noise sources add around the title — and, when the result names an author, that author to agree with the library row. A result with no author at all matches on title alone, which is the best that can be done for sources that publish nothing else.

type Match

type Match struct {
	ID    int64
	Title string
}

Match is a resolved ownership hit.

Jump to

Keyboard shortcuts

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