service

package
v1.2.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: 17 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 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.

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.
	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 (*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) 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