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 ¶
- func AuthorMatches(wantNormalized, raw string) bool
- func DefaultMediaType(mediaType string) string
- func KnownAuthor(author string) string
- func NormalizePerson(s string) string
- func NormalizeTitle(s string) string
- func NormalizeWords(s string) string
- func SplitAuthorList(author string) []string
- type Candidate
- type Index
- type Match
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthorMatches ¶
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 ¶
DefaultMediaType normalizes a possibly-empty media type. Search results from the ebook tab often carry no media type at all.
func KnownAuthor ¶
KnownAuthor returns the normalized author name, or "" when the field carries no usable name.
func NormalizePerson ¶
NormalizePerson folds an author name to its comparable form.
func NormalizeTitle ¶
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 ¶
NormalizeWords lowercases, drops punctuation and symbols, and collapses whitespace runs to a single space.
func SplitAuthorList ¶
SplitAuthorList splits a multi-author field on the separators sources actually use.
Types ¶
type Candidate ¶
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 (*Index) Lookup ¶
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.