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 LookupMode
- type LookupOptions
- type Match
- type RecordNotFoundError
- type Result
- type Service
- func (s *Service) Config() config.Config
- func (s *Service) Lookup(query string, opts LookupOptions) (*Result, 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 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
}
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.
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) Lookup ¶
func (s *Service) Lookup(query string, opts LookupOptions) (*Result, error)
Lookup resolves a query across the selected dictionaries.
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.