///|
/// MoonSearch is a MoonBit-native embedded full-text search kernel.
///
/// M5b aligns the analysis boundary with Tantivy: Tokenizer and TokenFilter
/// compose lazy TokenStreams, TextAnalyzer is itself a Tokenizer pipeline, and
/// TokenizerManager stores named Tokenizers used consistently by indexing and
/// query-time analysis. M5b-2 adds an `en_stem` pipeline with Porter2 English
/// stemming plus an optional stop-word filter. M5b-4a adds an optional,
/// dictionary-backed Chinese tokenizer package, and M5b-4b adds weighted DAG
/// routing without HMM. M5b-4c-1 adds portable, line-diagnosed dictionary text
/// resources, while M5b-4c-2 adds optional injected B/M/E/S HMM recognition;
/// M5c-1 adds validated Token Graph finite-string expansion for graph-aware
/// Boolean and Phrase query construction, and M5c-2 adds dictionary-gated
/// Chinese search-mode subword graphs. M5c-3 closes M5 with an index-flat
/// position policy that preserves precise cross-word phrases without changing
/// Segment persistence. M6a adds the standalone CLI, and M6b adds analyzer-
/// driven, UTF-8-safe result highlighting without persisted term vectors. M6c
/// adds deterministic benchmarks, while M6d reuses the root facade from a
/// browser-facing WasmGC demo. M6e moves large offline corpora into a Worker,
/// and M6f gives that Demo explicit English, Chinese, and multilingual Analyzer
/// Profiles with index/query-time graph discipline. M7 adds a strict,
/// UTF-8-spanned Query-string AST and Schema/Analyzer binding shared by the
/// Library, CLI, and Browser Wasm Demo. M8 adds the scalable cursor execution
/// core and Segment v3; M9 adds durable two-phase publication, writer locking,
/// Reader reload, recovery, CheckIndex, garbage collection, and merge policy.
/// M10 adds typed fields, columnar Fast Fields, Segment v4, typed filters,
/// sorting, collectors, facets, aggregations, and typed Query-string ranges.
/// M11 adds Segment v5 block postings, skip metadata, front-coded terms,
/// compressed lazy stored fields, safe WAND, budgeted flush, deterministic
/// segment execution plans, and merge backpressure. M12 adds multi-term and
/// compound query families, phrase slop/prefix, configurable scoring/explain,
/// lenient Query-string parsing, persisted-offset highlighting, character
/// filters, synonym graphs, and analyzer-resource compatibility checks.
/// N-gram remains a generic tool rather than Chinese word segmentation.
///
/// The root package is a compatibility facade over responsibility-focused
/// core, schema, analysis, index, query, and store packages.

///|
/// Stable root-package facade for MoonSearch's foundational value types.
pub using @core {
  type FieldId,
  type DocId,
  type DocAddress,
  type Document,
  type StoredDocument,
  type FieldValue,
  type Term,
  type PersistenceError,
}

///|
/// Stable root-package facade for schema construction and field options.
pub using @schema {
  type TextOptions,
  type FieldOptions,
  type FieldType,
  type Schema,
  type SchemaBuilder,
}

///|
/// Stable root-package facade for text analysis.
pub using @analysis {
  type Token,
  type TokenGraph,
  type TokenGraphPath,
  type AnalysisError,
  trait TokenStream,
  trait Tokenizer,
  type WhitespaceAnalyzer,
  type RawTokenizer,
  type WhitespaceTokenizer,
  type SimpleTokenizer,
  type NgramTokenizer,
  trait TokenFilter,
  type LowerCaseFilter,
  type RemoveLongFilter,
  type StopWordFilter,
  trait CharFilter,
  type CharFilterResult,
  type CharacterMapping,
  type MappingCharFilter,
  type CompatibilityNormalizationCharFilter,
  type SynonymRule,
  type SynonymGraphFilter,
  type AnalysisResource,
  type EnglishStemmerFilter,
  type TextAnalyzer,
  type TokenizerManager,
}

///|
/// Creates the English stemming pipeline exposed as the `en_stem` preset.
pub fn english_stem_analyzer() -> TextAnalyzer {
  @analysis.english_stem_analyzer()
}

///|
/// Stable root-package facade for optional dictionary-backed Chinese analysis.
pub using @chinese {
  type ChineseDictionaryResourceError,
  type ChineseHmmModelError,
  type ChineseHmmState,
  type ChineseLexiconError,
  type ChineseLexiconEntry,
  type ChineseWordMatch,
  trait ChineseDictionary,
  trait ChineseHmmModel,
  type ChineseLexicon,
  type ChineseSearchModeFilter,
  type ChineseTokenizer,
  type TableChineseHmmModel,
}

///|
/// Creates a lowercase Chinese analyzer around an injected dictionary.
pub fn chinese_analyzer(dictionary : &ChineseDictionary) -> TextAnalyzer {
  @chinese.chinese_analyzer(dictionary)
}

///|
/// Creates a longest-match Chinese analyzer with search-mode subwords.
pub fn chinese_search_analyzer(dictionary : &ChineseDictionary) -> TextAnalyzer {
  @chinese.chinese_search_analyzer(dictionary)
}

///|
/// Creates a longest-match Chinese search expansion for indexing.
pub fn chinese_search_index_analyzer(
  dictionary : &ChineseDictionary,
) -> TextAnalyzer {
  @chinese.chinese_search_index_analyzer(dictionary)
}

///|
/// Creates a lowercase Chinese analyzer using frequency-DAG routing.
pub fn chinese_dag_analyzer(dictionary : &ChineseDictionary) -> TextAnalyzer {
  @chinese.chinese_dag_analyzer(dictionary)
}

///|
/// Creates a Chinese DAG analyzer with search-mode subwords.
pub fn chinese_dag_search_analyzer(
  dictionary : &ChineseDictionary,
) -> TextAnalyzer {
  @chinese.chinese_dag_search_analyzer(dictionary)
}

///|
/// Creates a Chinese DAG search expansion for indexing.
pub fn chinese_dag_search_index_analyzer(
  dictionary : &ChineseDictionary,
) -> TextAnalyzer {
  @chinese.chinese_dag_search_index_analyzer(dictionary)
}

///|
/// Creates a lowercase Chinese DAG analyzer with injected HMM recognition.
pub fn chinese_dag_hmm_analyzer(
  dictionary : &ChineseDictionary,
  model : &ChineseHmmModel,
) -> TextAnalyzer {
  @chinese.chinese_dag_hmm_analyzer(dictionary, model)
}

///|
/// Creates a Chinese DAG/HMM analyzer with search-mode subwords.
pub fn chinese_dag_hmm_search_analyzer(
  dictionary : &ChineseDictionary,
  model : &ChineseHmmModel,
) -> TextAnalyzer {
  @chinese.chinese_dag_hmm_search_analyzer(dictionary, model)
}

///|
/// Creates a Chinese DAG/HMM search expansion for indexing.
pub fn chinese_dag_hmm_search_index_analyzer(
  dictionary : &ChineseDictionary,
  model : &ChineseHmmModel,
) -> TextAnalyzer {
  @chinese.chinese_dag_hmm_search_index_analyzer(dictionary, model)
}

///|
/// Stable root-package facade for immutable Segment construction and access.
pub using @index {
  type Posting,
  type PostingOccurrence,
  type PostingSkipBlock,
  type PostingCursor,
  type TermDictionary,
  type StoredFieldsReader,
  type FieldValueEntry,
  type FastFieldColumn,
  type SegmentWriter,
  type Segment,
  type BudgetedWriterStats,
  type BudgetedSegmentWriter,
  type IndexingExecutionPlan,
}

///|
/// Stable root-package facade for query construction, scoring, and search.
pub using @query {
  trait Query,
  trait Weight,
  trait Scorer,
  type TermQuery,
  type ExactQuery,
  type RangeQuery,
  type TermRangeQuery,
  type ExistsQuery,
  type PrefixQuery,
  type WildcardQuery,
  type RegexQuery,
  type FuzzyQuery,
  type MultiTermRewrite,
  type MatchAllQuery,
  type ConstantScoreQuery,
  type TermSetQuery,
  type DisjunctionMaxQuery,
  type BoostQuery,
  type Occur,
  type BooleanClause,
  type BooleanQuery,
  type PhraseQuery,
  type PhrasePrefixQuery,
  type BlockMaxWandQuery,
  type WandSearchResult,
  type QueryParser,
  type QueryStringErrorKind,
  type QueryStringError,
  type QueryLiteralMode,
  type UserQueryAst,
  type QueryStringParser,
  type LenientQueryResult,
  type HighlightMode,
  type HighlightSpan,
  type HighlightFragment,
  type HighlightOptions,
  type Highlighter,
  type SearchStatistics,
  type Bm25Scorer,
  type Bm25Config,
  type ConfiguredTermQuery,
  type ScoreFunction,
  type FunctionScoreQuery,
  type Explanation,
  type SearchHit,
  type TopKCollector,
  type TopDocsCollector,
  type CountCollector,
  type MultiCollector,
  type MultiCollectorResult,
  type SortOrder,
  type MissingValueOrder,
  type SortField,
  type Sort,
  type FacetCount,
  type RangeFacet,
  type RangeFacetCount,
  type HistogramBucket,
  type NumericAggregation,
  type Searcher,
  type SegmentSearchExecutor,
}

///|
/// Stable root-package facade for directory-backed index lifecycle APIs.
pub using @store {
  trait Directory,
  trait DirectoryV2,
  type DirectoryCapabilities,
  type MemoryDirectory,
  type FsDirectory,
  type MmapDirectory,
  type IndexWriter,
  type IndexReader,
  type MergePolicy,
  type MergeScheduler,
  type IndexCheckReport,
  type FaultInjectingDirectory,
  check_index,
}