Documentation
¶
Overview ¶
Package service is the application core: it owns the dictionary registry, picks parser profiles, resolves lookups and mints resource URLs.
Index ¶
- Variables
- type HTMLMarkdownOptions
- type LookupMode
- type LookupOptions
- type Match
- type RecordNotFoundError
- type Result
- type Service
- func (s *Service) Config() config.Config
- func (s *Service) EnableLookupLinks()
- func (s *Service) Lookup(query string, opts LookupOptions) (*Result, error)
- func (s *Service) LookupLinksEnabled() bool
- func (s *Service) MissingStylesheets(dict *mdict.Dictionary) []string
- func (s *Service) Navigate(from, to string, back bool)
- func (s *Service) PrepareAudio(token string, settings playback.Settings) ([]byte, error)
- func (s *Service) ProfileEvidence(dict *mdict.Dictionary) diagnose.ProfileEvidence
- func (s *Service) ProfileID(dict *mdict.Dictionary) string
- func (s *Service) Registry() *mdict.Registry
- func (s *Service) Rescan() error
- func (s *Service) ResolveResource(token string) (data []byte, contentType string, err error)
- func (s *Service) SetParserOverride(override string)
- func (s *Service) Transcoder() *resource.Transcoder
- func (s *Service) Uptime() time.Duration
Constants ¶
This section is empty.
Variables ¶
var ( ErrDictionaryNotFound = errors.New("dictionary ID not found") ErrRecordNotFound = errors.New("record ordinal not found") )
ErrDictionaryNotFound and ErrDictionaryUnavailable make a saved explicit ID failure distinguishable from a normal headword miss.
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.
type RecordNotFoundError ¶
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 (*Service) EnableLookupLinks ¶ added in v1.3.0
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
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
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
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) ResolveResource ¶
ResolveResource returns the bytes and content type behind a resource token.
func (*Service) SetParserOverride ¶ added in v1.1.0
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.