service

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-3.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package service is the application core: it owns the dictionary registry, picks parser profiles, resolves lookups and mints resource URLs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDictionaryNotFound    = errors.New("dictionary ID not found")
	ErrDictionaryUnavailable = errors.New("dictionary unavailable")
	ErrRecordNotFound        = errors.New("record ordinal not found")
)

ErrDictionaryNotFound and ErrDictionaryUnavailable make a saved explicit ID failure distinguishable from a normal headword miss.

View Source
var ErrNoDictionaries = errors.New("no dictionaries available")

ErrNoDictionaries means the user has not installed any dictionaries yet.

Functions

This section is empty.

Types

type HTMLMarkdownOptions added in v1.3.0

type HTMLMarkdownOptions struct {
	MultiRecordMode htmlmd.MultiRecordMode
	RecordOrdinal   int
}

HTMLMarkdownOptions configures the dictionary-layout Markdown view. It reads the same record selection fields as every other presentation, so a selector names the same record whichever view the reader chose.

type LookupMode

type LookupMode string

LookupMode controls how hard the service tries to find a headword.

const (
	// ModeExact prefers exact headword spelling, then accepts Unicode-normalized
	// and case-insensitive fallback matches. It never adds prefix suggestions.
	ModeExact LookupMode = "exact"
	// ModeSmart additionally offers prefix suggestions when nothing matched.
	ModeSmart LookupMode = "smart"
)

type LookupOptions

type LookupOptions struct {
	DictionaryIDs []string
	Mode          LookupMode
	// Limit caps how many dictionaries answer. Zero means all selected.
	Limit int
	// MaxExamples caps examples per sense.
	MaxExamples int
	Debug       bool
	// RenderBob adds a rendered toDict to the result.
	RenderBob bool
	// BobOptions configures that rendering.
	BobOptions bobadapter.Options
	// RenderMarkdown adds user Markdown rendered from the same EntrySet.
	RenderMarkdown  bool
	MarkdownOptions mdrender.Options
	// RenderPlain adds plain text rendered directly from the canonical EntrySet.
	RenderPlain  bool
	PlainOptions textrender.Options
	// RenderHTMLMarkdown adds Markdown converted from the first match's own
	// record HTML and stylesheets: the dictionary's layout rather than the
	// parser's reading of it.
	RenderHTMLMarkdown  bool
	HTMLMarkdownOptions HTMLMarkdownOptions
	// Playback is carried by 🔊 links that play in the background.
	Playback playback.Settings
}

LookupOptions configures a lookup.

type Match

type Match struct {
	DictionaryID    string `json:"dictionaryId"`
	DictionaryTitle string `json:"dictionaryTitle"`
	// LookupKey is the actual aggregate MDX key selected before duplicate
	// expansion. It remains distinct from parsed Headword and record-level
	// Source.MatchedKey provenance.
	LookupKey string                `json:"lookupKey"`
	Headword  string                `json:"headword"`
	Records   []entryir.EntryRecord `json:"records"`
	// ParseMillis is how long parsing took, for diagnostics.
	ParseMillis float64 `json:"parseMillis,omitempty"`
}

Match is one dictionary's answer to a lookup.

func (*Match) EntrySet added in v1.1.0

func (m *Match) EntrySet() *entryir.EntrySet

EntrySet rebuilds the canonical aggregate this match was rendered from.

It is the contract every presentation layer reads: the Bob adapter, and any other adapter, start here rather than from the wire shape of a Match.

type RecordNotFoundError

type RecordNotFoundError struct {
	Query     string
	Requested int
	Available int
}

RecordNotFoundError distinguishes an out-of-range presentation selector from a missing base headword.

func (*RecordNotFoundError) Error

func (e *RecordNotFoundError) Error() string

func (*RecordNotFoundError) Unwrap

func (e *RecordNotFoundError) Unwrap() error

type Result

type Result struct {
	Query   string  `json:"query"`
	Matches []Match `json:"matches"`
	// Bob is the ready-to-return toDict, present only when the caller asked
	// for it. Keeping it optional means the IR stays the canonical contract
	// and any other client can ignore Bob entirely.
	Bob *bobadapter.Dict `json:"bob,omitempty"`
	// Markdown is user-facing dictionary content, present only for
	// format:"markdown". Diagnostic provenance is never enabled here. With
	// markdownSource:"html" it is converted from the record's own HTML
	// instead of rendered from the EntrySet.
	Markdown string `json:"markdown,omitempty"`
	// Plain is a complete user-facing plain-text document. It is returned for
	// explicit plain requests and when a requested Bob card conservatively
	// falls back because the IR contains only free-form sections or weak,
	// untyped generic marker blocks.
	Plain string `json:"plain,omitempty"`
	// EffectiveFormat tells thin clients which presentation field is populated.
	// It is additive to API v2, so clients that know only bob/markdown can ignore it.
	EffectiveFormat string   `json:"effectiveFormat,omitempty"`
	Suggestions     []string `json:"suggestions,omitempty"`
}

Result is the full answer to a lookup request.

type Service

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

Service coordinates every component behind the HTTP API.

func New

func New(cfg config.Config) (*Service, error)

New builds a service. Dictionaries are discovered but not yet indexed.

func (*Service) Config

func (s *Service) Config() config.Config

Config exposes the resolved configuration.

func (s *Service) EnableLookupLinks()

EnableLookupLinks makes dictionary links in the web-layout view clickable lookups. The caller has made sure something handles them.

func (*Service) Lookup

func (s *Service) Lookup(query string, opts LookupOptions) (*Result, error)

Lookup resolves a query across the selected dictionaries.

func (*Service) LookupLinksEnabled added in v1.3.0

func (s *Service) LookupLinksEnabled() bool

LookupLinksEnabled reports whether dictionary links are rendered as links.

func (*Service) MissingStylesheets added in v1.3.0

func (s *Service) MissingStylesheets(dict *mdict.Dictionary) []string

MissingStylesheets reports the stylesheets a dictionary's sampled records link to but that cannot be found. It is measured from the same records that choose the profile, so it costs nothing beyond the rescan.

func (*Service) Navigate added in v1.3.0

func (s *Service) Navigate(from, to string, back bool)

Navigate records a step the reader took through a dictionary link: from one page to another, or back to the page before.

func (*Service) PrepareAudio added in v1.3.0

func (s *Service) PrepareAudio(token string, settings playback.Settings) ([]byte, error)

PrepareAudio returns the recording behind a resource token as a WAV file ready for the link helper to play.

func (*Service) ProfileEvidence added in v1.1.0

func (s *Service) ProfileEvidence(dict *mdict.Dictionary) diagnose.ProfileEvidence

ProfileEvidence re-runs detection for a dictionary and reports why the profile was chosen. Diagnostics only.

func (*Service) ProfileID

func (s *Service) ProfileID(dict *mdict.Dictionary) string

ProfileID returns the profile identifier for a dictionary, or "generic".

func (*Service) Registry

func (s *Service) Registry() *mdict.Registry

Registry exposes the dictionary registry.

func (*Service) Rescan

func (s *Service) Rescan() error

Rescan rediscovers dictionaries and rebuilds every index.

func (*Service) ResolveResource

func (s *Service) ResolveResource(token string) (data []byte, contentType string, err error)

ResolveResource returns the bytes and content type behind a resource token.

func (*Service) SetParserOverride added in v1.1.0

func (s *Service) SetParserOverride(override string)

SetParserOverride forces every dictionary onto one parser, for development comparisons between auto, generic and a named profile. It is a debugging aid with no persisted state; the product always runs on automatic detection.

func (*Service) Transcoder

func (s *Service) Transcoder() *resource.Transcoder

Transcoder exposes the audio transcoder.

func (*Service) Uptime

func (s *Service) Uptime() time.Duration

Uptime returns how long the service has been running.

Jump to

Keyboard shortcuts

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