Documentation
¶
Index ¶
- Constants
- Variables
- func AssetLookupCandidates(ref string) []string
- func AssetURL(basePath, ref string) string
- func BuildRangeTree(list []*MdictRecordBlockInfoListItem, root *RecordBlockRangeTreeNode)
- func ConfigureDictionaryPairAssets(spec DictionarySpec, mdxDict *Mdict, mddDicts ...*Mdict)
- func ExtractResourceRefs(content []byte) []string
- func IsResourceRef(ref string) bool
- func LookupAndRewriteHTML(dict *Mdict, word, assetBasePath string) ([]byte, error)
- func LookupAndRewriteHTMLWithEntryBase(dict *Mdict, word, assetBasePath, entryBasePath string) ([]byte, error)
- func NewAssetHandler(mdd *Mdict) http.Handler
- func NewAssetHandlerWithOptions(mdd *Mdict, opts AssetHandlerOptions) http.Handler
- func NormalizeMDDKey(name string) string
- func RewriteEntryAudioLinks(content []byte, assetBasePath string) []byte
- func RewriteEntryInternalLinks(content []byte) []byte
- func RewriteEntryLookupLinks(content []byte, entryBasePath string) []byte
- func RewriteEntryResourceURLs(content []byte, assetBasePath string) []byte
- type AssetHandlerOptions
- type AssetResolver
- type AssetResolverOption
- type AssetSource
- type Dictionary
- type DictionaryInfo
- type DictionaryRegistry
- func (r *DictionaryRegistry) LibrarySearch(query string, limit int) ([]LibrarySearchHit, error)
- func (r *DictionaryRegistry) List() []DictionarySpec
- func (r *DictionaryRegistry) LoadDirectory(root string) error
- func (r *DictionaryRegistry) LoadSpecs(specs []DictionarySpec)
- func (r *DictionaryRegistry) OpenDictionary(id string) (*Mdict, *Mdict, error)
- type DictionarySpec
- type EnsureIndexResult
- type FileStatFingerprinter
- type Fingerprinter
- type FingerprinterFunc
- type FuzzyIndexStore
- type IndexBuildLeaseStore
- type IndexEntry
- type IndexManifest
- type IndexStore
- type IndexSyncConfig
- type IndexSyncOption
- func WithClock(now func() time.Time) IndexSyncOption
- func WithFingerprinter(fp Fingerprinter) IndexSyncOption
- func WithForceRebuild() IndexSyncOption
- func WithMissingSourceTTL(ttl time.Duration) IndexSyncOption
- func WithRebuildLeasePollPeriod(period time.Duration) IndexSyncOption
- func WithRebuildLeaseTTL(ttl time.Duration) IndexSyncOption
- func WithReuseIfUnchanged(enabled bool) IndexSyncOption
- func WithSchemaVersion(version string) IndexSyncOption
- type LibrarySearchHit
- type MDictKeywordEntry
- type MDictKeywordIndex
- type MDictKeywordIndexRecordBlock
- type ManagedIndexStore
- type Mdict
- func (mdict *Mdict) AssetResolver() *AssetResolver
- func (mdict *Mdict) BuildIndex() error
- func (mdict *Mdict) CreationDate() string
- func (mdict *Mdict) Description() string
- func (mdict *Mdict) DictionaryInfo() DictionaryInfo
- func (mdict *Mdict) Digest() string
- func (mdict *Mdict) ExportEntries() ([]IndexEntry, error)
- func (mdict *Mdict) ExportIndex() ([]IndexEntry, error)
- func (mdict *Mdict) ExportResources() ([]IndexEntry, error)
- func (mdict *Mdict) FindComparableEntry(word string) (*MDictKeywordEntry, bool)
- func (mdict *Mdict) FindExactEntry(word string) (*MDictKeywordEntry, bool)
- func (mdict *Mdict) GeneratedByEngineVersion() string
- func (mdict *Mdict) GetKeyWordEntries() ([]*MDictKeywordEntry, error)
- func (mdict *Mdict) GetKeyWordEntriesSize() int64
- func (mdict *Mdict) IsMDD() bool
- func (mdict *Mdict) IsRecordEncrypted() bool
- func (mdict *Mdict) IsUTF16() bool
- func (mdict *Mdict) KeywordEntryToIndex(item *MDictKeywordEntry) (*MDictKeywordIndex, error)
- func (mdict *Mdict) LocateByKeywordEntry(entry *MDictKeywordEntry) ([]byte, error)
- func (mdict *Mdict) LocateByKeywordIndex(index *MDictKeywordIndex) ([]byte, error)
- func (mdict *Mdict) Lookup(word string) ([]byte, error)
- func (mdict *Mdict) Name() string
- func (mdict *Mdict) PrepareForExternalIndex() error
- func (mdict *Mdict) Resolve(entry IndexEntry) ([]byte, error)
- func (mdict *Mdict) ResolveEntry(entry *MDictKeywordEntry) ([]byte, error)
- func (mdict *Mdict) SetAssetResolver(resolver *AssetResolver)
- func (mdict *Mdict) Title() string
- func (mdict *Mdict) Version() string
- type MdictAccessor
- type MdictBase
- type MdictFS
- type MdictFile
- type MdictFileInfo
- func (mfi *MdictFileInfo) Info() (fs.FileInfo, error)
- func (mfi *MdictFileInfo) IsDir() bool
- func (mfi *MdictFileInfo) ModTime() time.Time
- func (mfi *MdictFileInfo) Mode() fs.FileMode
- func (mfi *MdictFileInfo) Name() string
- func (mfi *MdictFileInfo) Size() int64
- func (mfi *MdictFileInfo) Sys() interface{}
- func (mfi *MdictFileInfo) Type() fs.FileMode
- type MdictRecordBlockInfoListItem
- type MdictType
- type MemoryFuzzyIndexStore
- type MemoryIndexStore
- func (s *MemoryIndexStore) DeleteDictionary(dictionaryName string) error
- func (s *MemoryIndexStore) GetExact(dictionaryName, keyword string) (IndexEntry, error)
- func (s *MemoryIndexStore) LoadManifest(dictionaryName string) (IndexManifest, error)
- func (s *MemoryIndexStore) PrefixSearch(dictionaryName, prefix string, limit int) ([]IndexEntry, error)
- func (s *MemoryIndexStore) Put(info DictionaryInfo, entries []IndexEntry) error
- func (s *MemoryIndexStore) SaveManifest(manifest IndexManifest) error
- type RecordBlockRangeTreeNode
- type RedisIndexStore
- func (s *RedisIndexStore) AcquireIndexBuildLease(dictionaryName string, ttl time.Duration) (func() error, bool, error)
- func (s *RedisIndexStore) DeleteDictionary(dictionaryName string) error
- func (s *RedisIndexStore) GetExact(dictionaryName, keyword string) (IndexEntry, error)
- func (s *RedisIndexStore) LoadManifest(dictionaryName string) (IndexManifest, error)
- func (s *RedisIndexStore) PrefixSearch(dictionaryName, prefix string, limit int) ([]IndexEntry, error)
- func (s *RedisIndexStore) Put(info DictionaryInfo, entries []IndexEntry) error
- func (s *RedisIndexStore) SaveManifest(manifest IndexManifest) error
- type RedisIndexStoreOption
- type SearchHit
Constants ¶
const ( // MdictTypeMdd indicates an MDD file. MdictTypeMdd MdictType = 1 // MdictTypeMdx indicates an MDX file. MdictTypeMdx MdictType = 2 // EncryptNoEnc indicates no encryption. EncryptNoEnc = 0 // EncryptRecordEnc indicates record block encryption. EncryptRecordEnc = 1 // EncryptKeyInfoEnc indicates key info block encryption. EncryptKeyInfoEnc = 2 // NumfmtBe8bytesq represents big-endian 8-byte unsigned integer. NumfmtBe8bytesq = 0 // NumfmtBe4bytesi represents big-endian 4-byte unsigned integer. NumfmtBe4bytesi = 1 // EncodingUtf8 represents UTF-8 encoding. EncodingUtf8 = 0 // EncodingUtf16 represents UTF-16 encoding. EncodingUtf16 = 1 // EncodingBig5 represents Big5 encoding. EncodingBig5 = 2 // EncodingGbk represents GBK encoding. EncodingGbk = 3 // EncodingGb2312 represents GB2312 encoding. EncodingGb2312 = 4 // EncodingGb18030 represents GB18030 encoding. EncodingGb18030 = 5 )
Variables ¶
var ErrIndexMiss = errors.New("index entry not found")
ErrIndexMiss is returned when no entry exists in the external index store.
var ErrWordNotFound = errors.New("word not found")
ErrWordNotFound is returned when a word is not found in the dictionary.
Functions ¶
func AssetLookupCandidates ¶
AssetLookupCandidates expands a raw asset reference into possible storage lookup candidates.
func BuildRangeTree ¶
func BuildRangeTree(list []*MdictRecordBlockInfoListItem, root *RecordBlockRangeTreeNode)
BuildRangeTree constructs a range tree from a list of record block info items. This tree allows for efficient querying of record blocks based on an offset.
func ConfigureDictionaryPairAssets ¶ added in v0.1.10
func ConfigureDictionaryPairAssets(spec DictionarySpec, mdxDict *Mdict, mddDicts ...*Mdict)
ConfigureDictionaryPairAssets composes the default shared asset resolver for a dictionary pair.
func ExtractResourceRefs ¶
ExtractResourceRefs extracts resource-like references from MDX entry content.
func IsResourceRef ¶
IsResourceRef reports whether the reference looks like an external asset instead of an internal entry link.
func LookupAndRewriteHTML ¶
LookupAndRewriteHTML looks up an MDX entry and rewrites its asset URLs for web delivery.
func LookupAndRewriteHTMLWithEntryBase ¶ added in v0.1.10
func LookupAndRewriteHTMLWithEntryBase(dict *Mdict, word, assetBasePath, entryBasePath string) ([]byte, error)
LookupAndRewriteHTMLWithEntryBase looks up an MDX entry and rewrites its asset and entry URLs for web delivery.
func NewAssetHandler ¶
NewAssetHandler creates an HTTP handler that serves MDD-backed assets by raw reference name.
func NewAssetHandlerWithOptions ¶ added in v0.1.10
func NewAssetHandlerWithOptions(mdd *Mdict, opts AssetHandlerOptions) http.Handler
NewAssetHandlerWithOptions creates an HTTP handler that serves MDD-backed assets with configurable HTTP semantics.
func NormalizeMDDKey ¶
NormalizeMDDKey normalizes MDD resource names to the dictionary-internal key format.
func RewriteEntryAudioLinks ¶ added in v0.1.10
RewriteEntryAudioLinks rewrites anchor-based sound:// and snd:// links into HTML audio controls.
func RewriteEntryInternalLinks ¶ added in v0.1.10
RewriteEntryInternalLinks normalizes malformed internal entry links commonly seen in MDict HTML.
func RewriteEntryLookupLinks ¶ added in v0.1.10
RewriteEntryLookupLinks rewrites entry:// word links into browser-servable lookup URLs.
func RewriteEntryResourceURLs ¶
RewriteEntryResourceURLs rewrites asset references inside MDX HTML into browser-servable URLs.
Types ¶
type AssetHandlerOptions ¶ added in v0.1.10
AssetHandlerOptions configures HTTP delivery behavior for resolver-backed assets.
type AssetResolver ¶ added in v0.1.10
type AssetResolver struct {
// contains filtered or unexported fields
}
AssetResolver resolves dictionary assets from ordered sources and follows MDict-style redirects.
func NewAssetResolver ¶ added in v0.1.10
func NewAssetResolver(mdd *Mdict, opts ...AssetResolverOption) *AssetResolver
NewAssetResolver constructs an AssetResolver.
Ordered options are evaluated first. When mdd is non-nil it is appended after those sources, preserving GoldenDict-style sidecar-first precedence by default.
type AssetResolverOption ¶ added in v0.1.10
type AssetResolverOption func(*AssetResolver)
AssetResolverOption configures an AssetResolver.
func WithAssetMdicts ¶ added in v0.1.10
func WithAssetMdicts(dicts ...*Mdict) AssetResolverOption
WithAssetMdicts appends ordered MDD-backed asset sources to the resolver.
func WithAssetSidecarDir ¶ added in v0.1.10
func WithAssetSidecarDir(dir string) AssetResolverOption
WithAssetSidecarDir appends an on-disk sidecar directory used as a fallback source for assets.
func WithAssetSidecarFS ¶ added in v0.1.10
func WithAssetSidecarFS(fsys fs.FS) AssetResolverOption
WithAssetSidecarFS appends a sidecar filesystem used as a fallback source for assets.
func WithAssetSource ¶ added in v0.1.10
func WithAssetSource(source AssetSource) AssetResolverOption
WithAssetSource appends an ordered asset source to the resolver.
type AssetSource ¶ added in v0.1.10
AssetSource provides raw dictionary asset bytes for a logical reference.
type Dictionary ¶
type Dictionary struct {
XMLName xml.Name `xml:"Dictionary"`
Text string `xml:"chardata"`
GeneratedByEngineVersion string `xml:"GeneratedByEngineVersion,attr"`
RequiredEngineVersion string `xml:"RequiredEngineVersion,attr"`
Encrypted string `xml:"Encrypted,attr"`
Encoding string `xml:"Encoding,attr"`
IsUTF16 string `xml:"IsUTF16,attr"`
Format string `xml:"Format,attr"`
StripKey string `xml:"StripKey,attr"`
CreationDate string `xml:"CreationDate,attr"`
Compact string `xml:"Compact,attr"`
Compat string `xml:"Compat,attr"`
KeyCaseSensitive string `xml:"KeyCaseSensitive,attr"`
Description string `xml:"Description,attr"`
Title string `xml:"Title,attr"`
DataSourceFormat string `xml:"DataSourceFormat,attr"`
StyleSheet string `xml:"StyleSheet,attr"`
Left2Right string `xml:"Left2Right,attr"`
RegisterBy string `xml:"RegisterBy,attr"`
}
Dictionary was generated 2023-09-11 11:07:50 by https://xml-to-go.github.io/ in Ukraine.
type DictionaryInfo ¶
type DictionaryInfo struct {
Name string `json:"name"`
Title string `json:"title"`
Description string `json:"description"`
CreationDate string `json:"creation_date"`
GeneratedByEngineVersion string `json:"generated_by_engine_version"`
Version string `json:"version"`
IsMDD bool `json:"is_mdd"`
IsUTF16 bool `json:"is_utf16"`
IsRecordEncrypted bool `json:"is_record_encrypted"`
EntryCount int64 `json:"entry_count"`
}
DictionaryInfo describes dictionary metadata suitable for external indexing.
type DictionaryRegistry ¶
type DictionaryRegistry struct {
// contains filtered or unexported fields
}
DictionaryRegistry manages multiple dictionary pairs discovered from disk.
func NewDictionaryRegistry ¶
func NewDictionaryRegistry() *DictionaryRegistry
NewDictionaryRegistry creates an empty registry.
func (*DictionaryRegistry) LibrarySearch ¶
func (r *DictionaryRegistry) LibrarySearch(query string, limit int) ([]LibrarySearchHit, error)
LibrarySearch performs a library-wide fuzzy search using the in-memory fuzzy store.
func (*DictionaryRegistry) List ¶
func (r *DictionaryRegistry) List() []DictionarySpec
List returns the known dictionary specs.
func (*DictionaryRegistry) LoadDirectory ¶
func (r *DictionaryRegistry) LoadDirectory(root string) error
LoadDirectory scans and loads specs from a root directory into the registry.
func (*DictionaryRegistry) LoadSpecs ¶
func (r *DictionaryRegistry) LoadSpecs(specs []DictionarySpec)
LoadSpecs replaces the registry contents with the provided specs.
func (*DictionaryRegistry) OpenDictionary ¶
func (r *DictionaryRegistry) OpenDictionary(id string) (*Mdict, *Mdict, error)
OpenDictionary opens a dictionary pair by ID, lazily building indexes as needed.
type DictionarySpec ¶
type DictionarySpec struct {
ID string `json:"id"`
Name string `json:"name"`
MDXPath string `json:"mdx_path"`
MDDPath string `json:"mdd_path,omitzero"`
MDDPaths []string `json:"mdd_paths,omitempty"`
}
DictionarySpec describes one discoverable dictionary pair.
func ScanDirectory ¶
func ScanDirectory(root string) ([]DictionarySpec, error)
ScanDirectory scans a root directory for MDX/MDD pairs and returns their specs.
type EnsureIndexResult ¶ added in v0.1.12
type EnsureIndexResult struct {
DictionaryName string `json:"dictionary_name"`
Reused bool `json:"reused"`
Rebuilt bool `json:"rebuilt"`
Manifest IndexManifest `json:"manifest"`
}
EnsureIndexResult reports whether EnsureDictionaryIndex reused or rebuilt an index.
func EnsureDictionaryIndex ¶ added in v0.1.12
func EnsureDictionaryIndex(dictPath string, store ManagedIndexStore, opts ...IndexSyncOption) (*EnsureIndexResult, error)
EnsureDictionaryIndex ensures the external index for a dictionary is present and reusable.
type FileStatFingerprinter ¶ added in v0.1.12
type FileStatFingerprinter struct{}
FileStatFingerprinter fingerprints a dictionary source from cheap filesystem metadata.
func (FileStatFingerprinter) Fingerprint ¶ added in v0.1.12
func (FileStatFingerprinter) Fingerprint(path string) (string, error)
Fingerprint implements Fingerprinter.
type Fingerprinter ¶ added in v0.1.12
Fingerprinter computes a stable fingerprint for a dictionary source.
func NewFileStatFingerprinter ¶ added in v0.1.12
func NewFileStatFingerprinter() Fingerprinter
NewFileStatFingerprinter returns the default filesystem-stat fingerprinter.
type FingerprinterFunc ¶ added in v0.1.12
FingerprinterFunc adapts a function into a Fingerprinter.
func (FingerprinterFunc) Fingerprint ¶ added in v0.1.12
func (fn FingerprinterFunc) Fingerprint(path string) (string, error)
Fingerprint implements Fingerprinter.
type FuzzyIndexStore ¶
type FuzzyIndexStore interface {
Put(info DictionaryInfo, entries []IndexEntry) error
Search(dictionaryName, query string, limit int) ([]SearchHit, error)
}
FuzzyIndexStore defines a fuzzy-search-capable external index boundary.
type IndexBuildLeaseStore ¶ added in v0.1.15
type IndexBuildLeaseStore interface {
AcquireIndexBuildLease(dictionaryName string, ttl time.Duration) (release func() error, acquired bool, err error)
}
IndexBuildLeaseStore optionally coordinates index rebuild ownership across processes.
type IndexEntry ¶
type IndexEntry struct {
Keyword string `json:"keyword"`
NormalizedKeyword string `json:"normalized_keyword,omitempty"`
RecordStartOffset int64 `json:"record_start_offset"`
RecordEndOffset int64 `json:"record_end_offset"`
KeyBlockIdx int64 `json:"key_block_idx"`
IsResource bool `json:"is_resource"`
}
IndexEntry is the external-storage-friendly representation of a dictionary entry.
type IndexManifest ¶ added in v0.1.12
type IndexManifest struct {
DictionaryName string `json:"dictionary_name"`
SourcePath string `json:"source_path,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
SchemaVersion string `json:"schema_version,omitempty"`
BuiltAt time.Time `json:"built_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
IndexManifest describes externally stored index metadata used for lifecycle decisions.
func BuildIndexManifest ¶ added in v0.1.12
func BuildIndexManifest(dictPath string, dictName string, opts ...IndexSyncOption) (IndexManifest, error)
BuildIndexManifest builds a lifecycle manifest for the supplied dictionary source.
type IndexStore ¶
type IndexStore interface {
Put(info DictionaryInfo, entries []IndexEntry) error
GetExact(dictionaryName, keyword string) (IndexEntry, error)
PrefixSearch(dictionaryName, prefix string, limit int) ([]IndexEntry, error)
}
IndexStore defines the minimal external index boundary for exact and prefix search.
type IndexSyncConfig ¶ added in v0.1.12
type IndexSyncConfig struct {
ReuseIfUnchanged bool
MissingSourceTTL time.Duration
ForceRebuild bool
Fingerprinter Fingerprinter
Now func() time.Time
SchemaVersion string
RebuildLeaseTTL time.Duration
RebuildLeasePollPeriod time.Duration
}
IndexSyncConfig controls external-index lifecycle behavior.
func DefaultIndexSyncConfig ¶ added in v0.1.12
func DefaultIndexSyncConfig() IndexSyncConfig
DefaultIndexSyncConfig returns the default lifecycle configuration.
func ResolveIndexSyncConfig ¶ added in v0.1.12
func ResolveIndexSyncConfig(opts ...IndexSyncOption) IndexSyncConfig
ResolveIndexSyncConfig applies options onto the default configuration.
type IndexSyncOption ¶ added in v0.1.12
type IndexSyncOption func(*IndexSyncConfig)
IndexSyncOption customizes IndexSyncConfig.
func WithClock ¶ added in v0.1.12
func WithClock(now func() time.Time) IndexSyncOption
WithClock overrides the clock used for lifecycle calculations.
func WithFingerprinter ¶ added in v0.1.12
func WithFingerprinter(fp Fingerprinter) IndexSyncOption
WithFingerprinter overrides the source fingerprint implementation.
func WithForceRebuild ¶ added in v0.1.12
func WithForceRebuild() IndexSyncOption
WithForceRebuild forces index regeneration even when a manifest matches.
func WithMissingSourceTTL ¶ added in v0.1.12
func WithMissingSourceTTL(ttl time.Duration) IndexSyncOption
WithMissingSourceTTL sets how long an index may be reused after its source disappears.
func WithRebuildLeasePollPeriod ¶ added in v0.1.15
func WithRebuildLeasePollPeriod(period time.Duration) IndexSyncOption
WithRebuildLeasePollPeriod controls how often waiters re-check manifests while another process rebuilds.
func WithRebuildLeaseTTL ¶ added in v0.1.15
func WithRebuildLeaseTTL(ttl time.Duration) IndexSyncOption
WithRebuildLeaseTTL controls cross-process rebuild lease duration for stores that support it.
func WithReuseIfUnchanged ¶ added in v0.1.12
func WithReuseIfUnchanged(enabled bool) IndexSyncOption
WithReuseIfUnchanged toggles manifest fingerprint reuse.
func WithSchemaVersion ¶ added in v0.1.12
func WithSchemaVersion(version string) IndexSyncOption
WithSchemaVersion overrides the lifecycle schema version.
type LibrarySearchHit ¶
type LibrarySearchHit struct {
DictID string `json:"dict_id"`
DictName string `json:"dict_name"`
Hit SearchHit `json:"hit"`
}
LibrarySearchHit describes a search result together with its dictionary source.
type MDictKeywordEntry ¶
type MDictKeywordEntry struct {
RecordStartOffset int64
RecordEndOffset int64
KeyWord string
KeyBlockIdx int64
}
MDictKeywordEntry represents a single keyword entry from the key block.
type MDictKeywordIndex ¶
type MDictKeywordIndex struct {
//encoding int
//encryptType int
KeywordEntry MDictKeywordEntry
RecordBlock MDictKeywordIndexRecordBlock
}
MDictKeywordIndex provides a detailed index for a keyword, linking it to its specific location within a record block.
type MDictKeywordIndexRecordBlock ¶
type MDictKeywordIndexRecordBlock struct {
DataStartOffset int64
CompressSize int64
DeCompressSize int64
KeyWordPartStartOffset int64
KeyWordPartDataEndOffset int64
}
MDictKeywordIndexRecordBlock contains information about the record block where a specific keyword's definition is stored.
type ManagedIndexStore ¶ added in v0.1.12
type ManagedIndexStore interface {
IndexStore
LoadManifest(dictionaryName string) (IndexManifest, error)
SaveManifest(manifest IndexManifest) error
DeleteDictionary(dictionaryName string) error
}
ManagedIndexStore extends IndexStore with lifecycle metadata operations.
type Mdict ¶
type Mdict struct {
*MdictBase
// contains filtered or unexported fields
}
Mdict is a high-level wrapper for mdx/mdd dictionary files. It embeds MdictBase to handle the underlying parsing logic and provides a user-facing API.
func New ¶
New creates a new Mdict instance. It automatically determines the dictionary type based on the file extension (.mdx or .mdd).
func (*Mdict) AssetResolver ¶ added in v0.1.10
func (mdict *Mdict) AssetResolver() *AssetResolver
AssetResolver returns the shared asset resolver for this dictionary.
func (*Mdict) BuildIndex ¶
BuildIndex builds the complete dictionary index. This process can consume significant memory and time as it needs to read all keyword and record block information. It is recommended to call this once during program initialization.
func (*Mdict) CreationDate ¶
CreationDate returns the creation date of the dictionary.
func (*Mdict) Description ¶
Description returns the description of the dictionary.
func (*Mdict) DictionaryInfo ¶
func (mdict *Mdict) DictionaryInfo() DictionaryInfo
DictionaryInfo returns exported metadata for the current dictionary.
func (*Mdict) Digest ¶
Digest returns a string containing a summary of the Mdict object's metadata and internal structures. This is useful for debugging and understanding the contents of an MDX/MDD file.
func (*Mdict) ExportEntries ¶
func (mdict *Mdict) ExportEntries() ([]IndexEntry, error)
ExportEntries exports only MDX-style text entries.
func (*Mdict) ExportIndex ¶
func (mdict *Mdict) ExportIndex() ([]IndexEntry, error)
ExportIndex exports the in-memory dictionary index into storage-friendly entries.
func (*Mdict) ExportResources ¶
func (mdict *Mdict) ExportResources() ([]IndexEntry, error)
ExportResources exports only MDD-style resource entries.
func (*Mdict) FindComparableEntry ¶ added in v0.1.8
func (mdict *Mdict) FindComparableEntry(word string) (*MDictKeywordEntry, bool)
FindComparableEntry returns the normalized comparable keyword entry for the supplied word.
func (*Mdict) FindExactEntry ¶ added in v0.1.8
func (mdict *Mdict) FindExactEntry(word string) (*MDictKeywordEntry, bool)
FindExactEntry returns the exact keyword entry for the supplied word.
func (*Mdict) GeneratedByEngineVersion ¶
GeneratedByEngineVersion returns the engine version that generated the dictionary.
func (*Mdict) GetKeyWordEntries ¶
func (mdict *Mdict) GetKeyWordEntries() ([]*MDictKeywordEntry, error)
GetKeyWordEntries returns all keyword entries in the dictionary.
func (*Mdict) GetKeyWordEntriesSize ¶
GetKeyWordEntriesSize returns the total number of keyword entries in the dictionary.
func (*Mdict) IsRecordEncrypted ¶
IsRecordEncrypted checks if the dictionary's record blocks are encrypted.
func (*Mdict) KeywordEntryToIndex ¶
func (mdict *Mdict) KeywordEntryToIndex(item *MDictKeywordEntry) (*MDictKeywordIndex, error)
KeywordEntryToIndex converts a keyword entry to a more detailed keyword index.
func (*Mdict) LocateByKeywordEntry ¶
func (mdict *Mdict) LocateByKeywordEntry(entry *MDictKeywordEntry) ([]byte, error)
LocateByKeywordEntry locates and returns the definition by keyword entry.
func (*Mdict) LocateByKeywordIndex ¶
func (mdict *Mdict) LocateByKeywordIndex(index *MDictKeywordIndex) ([]byte, error)
LocateByKeywordIndex locates and returns the definition by keyword index.
func (*Mdict) Name ¶
Name returns the name of the dictionary, usually the filename without the extension.
func (*Mdict) PrepareForExternalIndex ¶ added in v0.1.12
PrepareForExternalIndex loads the minimum structures needed for ExportIndex and Resolve. It avoids building the in-memory exact/comparable lookup tables used by BuildIndex.
func (*Mdict) Resolve ¶
func (mdict *Mdict) Resolve(entry IndexEntry) ([]byte, error)
Resolve resolves previously exported index data back into dictionary content.
func (*Mdict) ResolveEntry ¶ added in v0.1.8
func (mdict *Mdict) ResolveEntry(entry *MDictKeywordEntry) ([]byte, error)
ResolveEntry resolves a keyword entry into dictionary content bytes.
func (*Mdict) SetAssetResolver ¶ added in v0.1.10
func (mdict *Mdict) SetAssetResolver(resolver *AssetResolver)
SetAssetResolver overrides the shared asset resolver for this dictionary.
type MdictAccessor ¶
type MdictAccessor struct {
Filepath string `json:"filepath"`
IsRecordEncrypted bool `json:"is_record_encrypted"`
IsMDD bool `json:"is_mdd"`
IsUTF16 bool `json:"is_utf_16"`
}
MdictAccessor provides a simplified interface for accessing Mdict data, suitable for serialization and remote access.
func NewAccessor ¶
func NewAccessor(mdict *Mdict) *MdictAccessor
NewAccessor creates a new MdictAccessor from an Mdict instance.
func NewAccessorFromJSON ¶
func NewAccessorFromJSON(data []byte) (*MdictAccessor, error)
NewAccessorFromJSON creates a new MdictAccessor from a JSON byte slice.
func (*MdictAccessor) RetrieveDefByIndex ¶
func (mdi *MdictAccessor) RetrieveDefByIndex(index *MDictKeywordIndex) ([]byte, error)
RetrieveDefByIndex retrieves a definition by its keyword index.
func (*MdictAccessor) Serialize ¶
func (mdi *MdictAccessor) Serialize() ([]byte, error)
Serialize converts the MdictAccessor to its JSON representation.
type MdictBase ¶
type MdictBase struct {
// contains filtered or unexported fields
}
MdictBase is the base structure for handling MDict file parsing. It contains all the necessary metadata and data structures read from the file.
func (*MdictBase) GetKeyWordEntries ¶
func (mdict *MdictBase) GetKeyWordEntries() ([]*MDictKeywordEntry, error)
GetKeyWordEntries returns all keyword entries in the dictionary.
type MdictFS ¶
type MdictFS struct {
// contains filtered or unexported fields
}
MdictFS wraps an Mdict instance to implement the io/fs.FS interface. This allows an MDX/MDD file to be accessed like a regular file system, for example, for an HTTP file server.
type MdictFile ¶
type MdictFile struct {
// contains filtered or unexported fields
}
MdictFile implements the fs.File interface.
type MdictFileInfo ¶
type MdictFileInfo struct {
// contains filtered or unexported fields
}
MdictFileInfo implements the fs.FileInfo interface.
func (*MdictFileInfo) Info ¶
func (mfi *MdictFileInfo) Info() (fs.FileInfo, error)
Info returns the FileInfo for the file.
func (*MdictFileInfo) IsDir ¶
func (mfi *MdictFileInfo) IsDir() bool
IsDir reports whether mfi describes a directory.
func (*MdictFileInfo) ModTime ¶
func (mfi *MdictFileInfo) ModTime() time.Time
ModTime returns the modification time.
func (*MdictFileInfo) Mode ¶
func (mfi *MdictFileInfo) Mode() fs.FileMode
Mode returns the file mode bits.
func (*MdictFileInfo) Name ¶
func (mfi *MdictFileInfo) Name() string
Name returns the base name of the file.
func (*MdictFileInfo) Size ¶
func (mfi *MdictFileInfo) Size() int64
Size returns the length in bytes for regular files.
func (*MdictFileInfo) Sys ¶
func (mfi *MdictFileInfo) Sys() interface{}
Sys returns underlying data source (can be nil).
func (*MdictFileInfo) Type ¶
func (mfi *MdictFileInfo) Type() fs.FileMode
Type returns the file's type.
type MdictRecordBlockInfoListItem ¶
type MdictRecordBlockInfoListItem struct {
// contains filtered or unexported fields
}
MdictRecordBlockInfoListItem holds information about a single record block.
func QueryRangeData ¶
func QueryRangeData(root *RecordBlockRangeTreeNode, queryRange int64) *MdictRecordBlockInfoListItem
QueryRangeData queries the range tree to find the record block info item that contains the given queryRange offset.
type MdictType ¶
type MdictType int
MdictType represents the type of the dictionary file (MDX or MDD).
type MemoryFuzzyIndexStore ¶
type MemoryFuzzyIndexStore struct {
// contains filtered or unexported fields
}
MemoryFuzzyIndexStore is a small in-memory reference implementation of FuzzyIndexStore.
func NewMemoryFuzzyIndexStore ¶
func NewMemoryFuzzyIndexStore() *MemoryFuzzyIndexStore
NewMemoryFuzzyIndexStore creates a new in-memory fuzzy store.
func (*MemoryFuzzyIndexStore) Put ¶
func (s *MemoryFuzzyIndexStore) Put(info DictionaryInfo, entries []IndexEntry) error
Put stores dictionary metadata and entries.
type MemoryIndexStore ¶
type MemoryIndexStore struct {
// contains filtered or unexported fields
}
MemoryIndexStore is a small in-memory reference implementation of ManagedIndexStore.
func NewMemoryIndexStore ¶
func NewMemoryIndexStore() *MemoryIndexStore
NewMemoryIndexStore creates a new in-memory store.
func (*MemoryIndexStore) DeleteDictionary ¶ added in v0.1.12
func (s *MemoryIndexStore) DeleteDictionary(dictionaryName string) error
DeleteDictionary removes one dictionary's entries and manifest.
func (*MemoryIndexStore) GetExact ¶
func (s *MemoryIndexStore) GetExact(dictionaryName, keyword string) (IndexEntry, error)
GetExact retrieves a single exact-match entry.
func (*MemoryIndexStore) LoadManifest ¶ added in v0.1.12
func (s *MemoryIndexStore) LoadManifest(dictionaryName string) (IndexManifest, error)
LoadManifest returns lifecycle metadata for one dictionary.
func (*MemoryIndexStore) PrefixSearch ¶
func (s *MemoryIndexStore) PrefixSearch(dictionaryName, prefix string, limit int) ([]IndexEntry, error)
PrefixSearch returns entries that start with the supplied prefix.
func (*MemoryIndexStore) Put ¶
func (s *MemoryIndexStore) Put(info DictionaryInfo, entries []IndexEntry) error
Put stores dictionary metadata and entries.
func (*MemoryIndexStore) SaveManifest ¶ added in v0.1.12
func (s *MemoryIndexStore) SaveManifest(manifest IndexManifest) error
SaveManifest stores lifecycle metadata for one dictionary.
type RecordBlockRangeTreeNode ¶
type RecordBlockRangeTreeNode struct {
// contains filtered or unexported fields
}
RecordBlockRangeTreeNode represents a node in the record block range tree. This tree is used to efficiently find the record block corresponding to a given offset.
type RedisIndexStore ¶
type RedisIndexStore struct {
// contains filtered or unexported fields
}
RedisIndexStore is a Redis-backed reference implementation of ManagedIndexStore.
func NewRedisIndexStore ¶
func NewRedisIndexStore(client *redis.Client, opts ...RedisIndexStoreOption) *RedisIndexStore
NewRedisIndexStore creates a Redis-backed store.
func (*RedisIndexStore) AcquireIndexBuildLease ¶ added in v0.1.15
func (s *RedisIndexStore) AcquireIndexBuildLease(dictionaryName string, ttl time.Duration) (func() error, bool, error)
AcquireIndexBuildLease coordinates dictionary index rebuild ownership across processes.
func (*RedisIndexStore) DeleteDictionary ¶ added in v0.1.12
func (s *RedisIndexStore) DeleteDictionary(dictionaryName string) error
DeleteDictionary removes one dictionary's entries and manifest.
func (*RedisIndexStore) GetExact ¶
func (s *RedisIndexStore) GetExact(dictionaryName, keyword string) (IndexEntry, error)
GetExact returns one exact entry from Redis.
func (*RedisIndexStore) LoadManifest ¶ added in v0.1.12
func (s *RedisIndexStore) LoadManifest(dictionaryName string) (IndexManifest, error)
LoadManifest returns lifecycle metadata for one dictionary.
func (*RedisIndexStore) PrefixSearch ¶
func (s *RedisIndexStore) PrefixSearch(dictionaryName, prefix string, limit int) ([]IndexEntry, error)
PrefixSearch returns entries that share the supplied prefix.
func (*RedisIndexStore) Put ¶
func (s *RedisIndexStore) Put(info DictionaryInfo, entries []IndexEntry) error
Put stores dictionary metadata and index entries in Redis.
func (*RedisIndexStore) SaveManifest ¶ added in v0.1.12
func (s *RedisIndexStore) SaveManifest(manifest IndexManifest) error
SaveManifest stores lifecycle metadata for one dictionary.
type RedisIndexStoreOption ¶
type RedisIndexStoreOption func(*RedisIndexStore)
RedisIndexStoreOption customizes RedisIndexStore construction.
func WithRedisIndexContext ¶
func WithRedisIndexContext(ctx context.Context) RedisIndexStoreOption
WithRedisIndexContext overrides the store context.
func WithRedisKeyPrefix ¶
func WithRedisKeyPrefix(prefix string) RedisIndexStoreOption
WithRedisKeyPrefix overrides the Redis key namespace prefix.
func WithRedisPrefixIndexMaxLen ¶
func WithRedisPrefixIndexMaxLen(maxLen int) RedisIndexStoreOption
WithRedisPrefixIndexMaxLen overrides the maximum stored prefix length.
type SearchHit ¶
type SearchHit struct {
Entry IndexEntry `json:"entry"`
Score float64 `json:"score"`
Source string `json:"source"`
}
SearchHit represents a ranked search result from a fuzzy-capable store.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
http-library
command
|
|
|
http-server
command
|
|
|
http-server-redis
command
|
|
|
redis-index
command
|